Inventor Customization

Reply
Contributor
Posts: 16
Registered: ‎04-11-2012
Message 1 of 11 (678 Views)

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

678 Views, 10 Replies
04-11-2012 06:51 AM

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)

*Expert Elite*
Curtis_Waguespack
Posts: 2,568
Registered: ‎03-08-2006
Message 2 of 11 (664 Views)

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

04-11-2012 02:56 PM in reply to: Gwennberg

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

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Contributor
Posts: 16
Registered: ‎04-11-2012
Message 3 of 11 (635 Views)

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

04-16-2012 06:56 AM in reply to: Curtis_Waguespack

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

Active Member
ben.young
Posts: 7
Registered: ‎10-04-2011
Message 4 of 11 (588 Views)

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

05-02-2012 01:24 AM 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 blog:smileyhappy:)

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.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Product Design Suite Ultimate 2012 64-bit - SP1
Windows 7 64-bit - SP1
Active Member
ben.young
Posts: 7
Registered: ‎10-04-2011
Message 5 of 11 (587 Views)

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

05-02-2012 01:27 AM 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)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Product Design Suite Ultimate 2012 64-bit - SP1
Windows 7 64-bit - SP1
Contributor
Posts: 16
Registered: ‎04-11-2012
Message 6 of 11 (537 Views)

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

05-14-2012 09:27 AM 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

ADN Support Specialist
Posts: 288
Registered: ‎07-21-2006
Message 7 of 11 (531 Views)

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

05-14-2012 10:23 AM 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
Developer Technical Services
Autodesk Developer Network
Autodesk, Inc.
Active Member
ben.young
Posts: 7
Registered: ‎10-04-2011
Message 8 of 11 (527 Views)

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

05-14-2012 10:57 AM 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.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Product Design Suite Ultimate 2012 64-bit - SP1
Windows 7 64-bit - SP1
Active Member
ben.young
Posts: 7
Registered: ‎10-04-2011
Message 9 of 11 (526 Views)

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

05-14-2012 11:02 AM 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.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Product Design Suite Ultimate 2012 64-bit - SP1
Windows 7 64-bit - SP1
*Expert Elite*
Curtis_Waguespack
Posts: 2,568
Registered: ‎03-08-2006
Message 10 of 11 (523 Views)

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

05-14-2012 11:31 AM in reply to: Gwennberg

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




  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube