Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create both PDF-file of the drawing and a STEP of the connected 3d-file

10 REPLIES 10
Reply
Message 1 of 11
Gwennberg
1485 Views, 10 Replies

How to create both PDF-file of the drawing and a STEP of the connected 3d-file

Hi

I have a script that makes PDF-file with suffix revision. Now I want to expand this script so it even makes a STEP-file of the 3d-file connected to the drawing. This would make all manufacture files in one button. That should be nice..

How will i manage with this since the active document is the drawing not the part. (see code below)

BR/Goran

 

Set oDoc = ThisApplication.ActiveDocument

Call oDoc.SaveAs("C:\Users\GoranWe\Desktop\test\testfile.stp", True)

Tags (2)
10 REPLIES 10
Message 2 of 11

Hi Gwennberg, 

When working with a drawing file you can use ThisDoc.ModleDocument to reference the model.

 

Below is an example.

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

'-------------export PDF  file -------------------------------
'Save PDF with options
Dim oDocument As Inventor.DrawingDocument
oDocument = ThisDoc.Document
path_and_name = ThisDoc.PathAndFileName(False) ' without extension
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
'oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If

'Set the destination file name
oDataMedium.FileName = path_and_name & ".pdf"

'Publish document.
Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

'-------------export step file -------------------------------
'define the model referenced by the drawing
Dim oModelDoc = ThisDoc.ModelDocument
' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oSTEPContext As TranslationContext
oSTEPContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oSTEPOptions As NameValueMap
oSTEPOptions = ThisApplication.TransientObjects.CreateNameValueMap

If oSTEPTranslator.HasSaveCopyAsOptions(oModelDoc, oSTEPContext, oSTEPOptions) Then
    ' Set application protocol.
    ' 2 = AP 203 - Configuration Controlled Design
    ' 3 = AP 214 - Automotive Design
    oSTEPOptions.Value("ApplicationProtocolType") = 3
    ' Other options...
    'oSTEPOptions.Value("Author") = ""
    'oSTEPOptions.Value("Authorization") = ""
    'oSTEPOptions.Value("Description") = ""
    'oSTEPOptions.Value("Organization") = ""
    oSTEPContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    Dim oData As DataMedium
    oData = ThisApplication.TransientObjects.CreateDataMedium
    oData.FileName = ThisDoc.PathAndFileName(False) & ".stp"
oSTEPTranslator.SaveCopyAs(oModelDoc, oSTEPContext, oSTEPOptions, oData)
End If

 

Message 3 of 11

Hi

I pasted your script as it was written into editorn but I got failure in the definition: 

"Dim oModelDoc = ThisDoc.ModelDocument".  Whats wrong?

 

/Goran

Message 4 of 11
ben.young
in reply to: Gwennberg

Goran, have you got the STP output working?

I've created iLogic rules for exporting PDF, DXF & STP. (With help from Curtis Waguespack's From the Trences blogSmiley Happy)

The iLogic code that I use looks like this:

 

'define the model referenced by the drawing
Dim oModelDoc = ThisDoc.ModelDocument
' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
If oSTEPTranslator.HasSaveCopyAsOptions(oModelDoc, oContext, oOptions) Then

'Options for STEP output
oOptions.Value("ApplicationProtocolType") = 3 'Set application protocol: 2 = AP 203 - Configuration Controlled Design, 3 = AP 214 - Automotive Design
oOptions.Value("Author") = ThisApplication.GeneralOptions.UserName
oOptions.Value("Authorization") = ""
oOptions.Value("Tolerance") = "0.00001 mm"
oOptions.Value("Description") = iProperties.Value("Summary", "Title")
oOptions.Value("Organization") = "IKM Technique AS"

oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium

FilePath= ThisDoc.Path 'This .IDW's path
OutputPath = FilePath & "\" & "STP" 'Output destination for the new STP
OutputFileName = iProperties.Value("Custom", "Output File Name") & ".stp" 'Output File Name as specified in Custom iProperties, as specified by the iLogic rule OutputFileName

'Check for existance of STP folder and create if not found
If Not System.IO.Directory.Exists(OutputPath) Then
System.IO.Directory.CreateDirectory(OutputPath)
End If
'Set the destination path & file name
oData.FileName = OutputPath & "\" & OutputFileName

'Publish Document
oSTEPTranslator.SaveCopyAs(oModelDoc, oContext, oOptions, oData)
End If

 

I also export drawings with a revision suffix. I have another iLogic rule which runs automatically (Event Triggers) everytime the drawing is saved. This iLogic rule creates a custom iProperty containing current revision, which is used for the file names of the exported PDF, DXF and STP files. Which is why I specify export destination and file name the way I do.

Message 5 of 11
ben.young
in reply to: Gwennberg

Another way to retrieve model path and file name is by using this code:

 

ModelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
ModelPath = IO.Path.GetDirectoryName(ThisDrawing.ModelDocument.FullFileName)
Message 6 of 11
Gwennberg
in reply to: Gwennberg

Hi Ben Young

I pasted your script as it was written into editorn but I got failure this time also.

It will not accept syntax "Dim oModelDoc = ThisDoc.ModelDocument".  Whats wrong?

 

BR

/Goran

Message 7 of 11
ekinsb
in reply to: Gwennberg

It's not a simple matter of getting the model from the drawing since it's possible for drawing to reference multiple files.  One approach is to use the ReferencedDocuments property of the DrawingDocument to get a list of documents directly referenced by the drawing.  You can then write these out in whatever format you want.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 8 of 11
ben.young
in reply to: Gwennberg

I don't know why that didn't work for you. It works on all of the machines at my workplace.

What I posted was actually the from the 2nd time I wrote the script. I'll see if I can dig up the first version of it. It calls up the model in a slightly different way.


I'll get back to you.

Message 9 of 11
ben.young
in reply to: ekinsb

That's a good point.

Though, the reason why it works for us is that we have only one part or one assembly per drawing.

Message 10 of 11

Hi Gwennberg, 

 

ekinsb's point is a very good one, and writing the code to identify a specific view and the model referenced by that view would be more robust, albeit a bit more involved. 

 

Most times when we are saving a file to a STEP (around here) it is a Part file and that part file is the only one referenced on the drawing, but if that's not the case for you this code might not work for you as is.

 

As for your problems running this code, is it possible that you're trying to run this rule from the VBA editor rather than as an iLogic rule? Both of the examples are written for iLogic.

 

Here's a link that will help you set this up as an iLogic rule:

http://inventortrenches.blogspot.com/2012/01/creating-basic-ilogic-rule-with-event.html

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com


Message 11 of 11
Gwennberg
in reply to: Gwennberg

Hi,

I have worked thought VBA editor so that must be the reason why it not works.

I also see the problem with many parts in a drawing but it would not be any problem since we never makes drawing that way.

 

Thanks agin all of you for your help.

 

BR/Göran

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report