static void TestDocument(DraftDocument document) { if (Program._extractEMFs) { foreach (Sheet sheet in document.Sheets) { log.Debug(String.Format("Extracting sheet '{0}'", sheet.Name)); sheet.SaveAsEmf(Path.ChangeExtension(document.FileName, String.Format("{0}.emf", sheet.Name))); } } }
/// <summary> /// Opens a draft file directly and extracts each sheet as an image. /// </summary> static void ExportFromClosedFile(Options options) { // Make sure the file exists. if (File.Exists(options.FileName)) { // Open the file. using (var draftDocument = DraftDocument.Open(options.FileName)) { // Get the path to the file. var exportPath = Path.GetDirectoryName(options.FileName); // Get the file name without the extension. var baseFileName = Path.GetFileNameWithoutExtension(options.FileName); // Build the base path to the new file. baseFileName = Path.Combine(exportPath, baseFileName); // Process each sheet. foreach (var sheet in draftDocument.Sheets) { // Build the base path & filename of the image. var baseSheetFileName = String.Format("{0} ({1})", baseFileName, sheet.Index); // Sheets native viewer format is EMF so they can be exported directly. if (options.ExportEMF) { // Build full path to EMF. var emfFileName = String.Format("{0}.emf", baseSheetFileName); // Save EMF. sheet.SaveAsEmf(emfFileName); Console.WriteLine("Extracted '{0}'.", emfFileName); } // Other formats must go through a vector to raster conversion process. // This conversion process can be slow. The reason is that most drawings // have large dimensions. You may consider resizing during the conversion. if (options.IsRasterImageFormatSpecified) { // Get a new instance of Metafile from sheet. using (var metafile = sheet.GetMetafile()) { ExportMetafile(metafile, baseSheetFileName, options); } } } } } else { throw new FileNotFoundException("File not found.", options.FileName); } }
public override async Task SetUp() { InitializeClient(); Account = (await Client.Accounts.GetAccountsAsync(0, 1)).Accounts[0]; var cert = (await Client.Accounts.GetAccountCertificatesAsync(Account.Id)).Certificates[0]; validDraftMetaRequest = new DraftMetaRequest { Payer = new AccountInfoRequest { Inn = cert.Inn, Organization = new OrganizationInfoRequest { Kpp = cert.Kpp } }, Sender = new SenderRequest { Inn = cert.Inn, Kpp = cert.Kpp, IpAddress = "8.8.8.8", Certificate = new CertificateRequest { Content = cert.Content } }, Recipient = new RecipientInfoRequest { FssCode = "11111" } }; draft = await CreateDraftAsync(); emptyDocument = await CreateEmptyDocument(); filledDocument = await CreateFilledDocument(draft); filledDocumentSignature = await Client.Drafts.AddDocumentSignatureAsync( Account.Id, draft.Id, filledDocument.Id, new SignatureRequest { Base64Content = Convert.ToBase64String(new byte[] { 1, 2, 3, 4 }) }); }
void doc_OnCloseEditor(object sender, DraftDocument.Events.CloseArg args) { }
static void Main(string[] args) { string folder = ConfigurationManager.AppSettings.Get("saveFolder"); Application application = null; SolidEdgeDocument activeDocument = null; try { // See "Handling 'Application is Busy' and 'Call was Rejected By Callee' errors" topic. OleMessageFilter.Register(); // Attempt to connect to a running instance of Solid Edge. application = (Application)Marshal.GetActiveObject("SolidEdge.Application"); //get active document activeDocument = (SolidEdgeDocument)application.ActiveDocument; //execute different behaviour for different documet type switch (GetDocumentType(application.ActiveDocument)) //grab document type form active document { case DocumentTypeConstants.igDraftDocument: Console.WriteLine("Grabbed draft document"); SaveAsExtension(activeDocument, folder, "dxf"); //save the active document on the specified folder as dxf SaveAsExtension(activeDocument, folder, "pdf"); //save the active document on the specified folder as pdf DraftDocument activeDraft = (DraftDocument)application.ActiveDocument; //cast the active document as a draftDocument to access the model link foreach (ModelLink modelLink in activeDraft.ModelLinks) //loop for all model links found in the model link { if (GetDocumentType((SolidEdgeDocument)modelLink.ModelDocument) == DocumentTypeConstants.igPartDocument) { SaveAsExtension((SolidEdgeDocument)modelLink.ModelDocument, folder, "stp"); // cast the individual modelLlink.ModelDocument as a model document and save it break; } if (GetDocumentType((SolidEdgeDocument)modelLink.ModelDocument) == DocumentTypeConstants.igAssemblyDocument) { SolidEdgeDocument asmDocument = (SolidEdgeDocument)modelLink.ModelDocument; // cast the individual modelLlink.ModelDocument as a model document if (asmDocument.Name.Contains("MPF")) // quick string check if contains the letters MPF { Console.WriteLine("Found MPF named document: " + asmDocument.Name); SaveAsExtension((SolidEdgeDocument)modelLink.ModelDocument, folder, "stp"); //save the model link document on the specified folder as stp break; } else { Console.WriteLine("Found an non MPF asembly document: " + asmDocument.Name); // found nothing here } } } break; case DocumentTypeConstants.igPartDocument: Console.WriteLine("Grabbed part document"); SaveAsExtension(activeDocument, folder, "stp"); // save the part document in the specified folder as stp break; default: Console.WriteLine("No valid document"); // found nothing here break; } Console.WriteLine("Todo ha salido a pedir de Milhouse"); Console.ReadKey(); } catch (Exception e) { Console.WriteLine(e.Message); throw; } finally { OleMessageFilter.Unregister(); // unlink application after completion } }