Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Getting iLogic rule to save triggerd parts individually

phila
Enthusiast

Getting iLogic rule to save triggerd parts individually

phila
Enthusiast
Enthusiast

I have an iLogic rule to run on IPT's and some IAM's after the file saves to a STEP FILES folder.

The upper assemblies typically do not have the trigger set to save as a STEP file.

 

When in the context of an upper assembly, that does not have the trigger, and a save is done, the entire upper assembly is saved to a STEP file with the correct name of the lower level IPT/IAM that has a trigger. Unfortunately the STEP file contains the assembly not the individual part or respective assembly.

 

It works perfectly in the individual files but if I'm not careful, it overwrite the existing file with the assembly. Not good.

 

I think my problem, aside not knowing programming, is with the "Stepfilename = Thisdoc.path". Since I am in an upper assembly, it makes sense that would be the Thisdoc.path I'm in and not the individual file that has a trigger.

 

Stepfilename = ThisDoc.Path & "\STEP FILES\" & ThisDoc.FileName(False)

 

How do I get the rule to save each file, that has a trigger, to their respective file and path?

Hope this makes sense.

 

0 Likes
Reply
Accepted solutions (1)
2,169 Views
24 Replies
Replies (24)

phila
Enthusiast
Enthusiast

Makes sense. I think.

 

At this point I don't know where to add the code or what changes are needed to get it to work. My attempt:

 

Tried pasting the All Referenced Documents code above the call to StepTranslator and get an error that "All other subs or functions must be after Sub Main()"

 

Removed the Debug print part.

 

Changed the line

 

oSTEPTranslator.SaveCopyAs(ThisApplication.oRefDoc.DisplayName, oContext, oOptions, oData)

 

Obviously not the way to do it.

 

How is it implemented?

0 Likes

phila
Enthusiast
Enthusiast

I have tried to figure this out without success. Did searches on the error trying to understand what it means. All the results so far assume you know VB like the back of your hand to begin with in their explainations. I don't know enough other than to be dangerous about writing code.

 

Can't get the examples given on the site referenced to work, same Sub Main  error. Seems they have to run within a greater program.

 

Completly stumped.

 

Is there a way to get the All Referenced Dociuments code to sequence through and create the STEP files? Of course there is, but how?

0 Likes

phila
Enthusiast
Enthusiast

Figured out the link examples are VB not ilogic. Seem to be two entirely different worlds. Each sub? may or may not work in VB or VB in ilogic. First line returns a compile error for the text that is to show in the dialog box. Works in iLogic not VB. I'm lost.

 

Once again, I am asking for help/direction/pay you on how to get this to work?

 

 

0 Likes

MechMachineMan
Advisor
Advisor

Here's a a few links that has a bit more on Sub Main() / End Sub and AllReferencedDocuments

 

http://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

 

http://au.autodesk.com/au-online/classes-on-demand/search?full-text=Inventor+iLogic&productName=&lan...

 

>> This one specifically: http://au.autodesk.com/au-online/classes-on-demand/class-catalog/2013/product-design-suite/ma1936#ch...


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes

phila
Enthusiast
Enthusiast
Accepted solution

Thanks for the additional links. I will look at them.

 

I finally got this to work as I wanted.

 

Added:

oODocName = ThisDoc.Document

 

and changed the line

oSTEPTranslator.SaveCopyAs(oODocName, oContext, oOptions, oData)

 

It now saves the correct STEP and fortunately in the correct folders of the different products as well. Got lucky.

 

Here is the rule as it is now:

 

' Start of iLogic code *******************************************

'query user

question = MessageBox.Show("Is a STEP file needed for " & ThisDoc.FileName(False), "Sav2STEP",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

'set condition based on answer

If question = vbNo Then

Exit Sub

End If

 

oODocName = ThisDoc.Document

oPath=ThisDoc.Path

oFolder = oPath & "\STEP FILES"

oRevNum = iProperties.Value("Project", "Revision Number")

 

'check to see if in drawing

If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then

doc = ThisApplication.ActiveDocument

MsgBox("This iLogic rule will only run from a part or assembly", MsgBoxStyle.Exclamation, "Document Type Error")

Exit Sub

End If

Dim Sdate As String = DateString '& " " & TimeString

'Check for the STEP folder and create it if it does not exist

If Not System.IO.Directory.Exists(oFolder) Then

System.IO.Directory.CreateDirectory(oFolder)

End If

 

'Delete Files from folder containing this file name

Dim path As String = ThisDoc.Path & "\STEP FILES\"

For Each foundFile As String In My.Computer.FileSystem.GetFiles (path,Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories,

"*" & ThisDoc.FileName(False) & "*")

My.Computer.FileSystem.DeleteFile(foundFile)

Next

 

'Start of export code ***********************************************

' 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(ThisApplication.ActiveDocument _

, oContext, oOptions) Then

oOptions.Value("ApplicationProtocolType") = 3

oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

Dim oData As DataMedium

oData = ThisApplication.TransientObjects.CreateDataMedium

 

' Set export name of STEP file

oData.FileName =ThisDoc.Path & "\STEP FILES\" & ThisDoc.FileName(False) & " " & oRevNum & ".stp"

'oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)

oSTEPTranslator.SaveCopyAs(oODocName, oContext, oOptions, oData)

End If

 

' End of export code ***********************************************

 

' Ask user if they want to open the export folder

OpenFolder = MessageBox.Show("Export successful! " & _

"- open containing folder now?", "Sav2STEP", _

MessageBoxButtons.YesNo, _

MessageBoxIcon.Question,MessageBoxDefaultButton.Button1)

 

If OpenFolder = vbYes Then

Process.Start("explorer.exe", ThisDoc.Path & "\STEP FILES\")

Else ' User says continue

'Return

End If

 

' End of iLogic code **************************************************

 

0 Likes