Get Ilogic code to wait before running the rest of the code?

Get Ilogic code to wait before running the rest of the code?

briant.markham
Enthusiast Enthusiast
4,368 Views
12 Replies
Message 1 of 13

Get Ilogic code to wait before running the rest of the code?

briant.markham
Enthusiast
Enthusiast

I have the code below, if I make the first and second blocks into seperate rules it runs perfectly, but If I try to run them sequentially in one rule or call both seperate rules from another rule, the second block runs before the first is completed and the desired result is missed. Is there a way to make sure the first block finishes completely before the 2nd block does it's thing?

 

 

Dim oDraw As DrawingDocument
oDraw = ThisApplication.ActiveDocument
oDraw.DrawingSettings.PreserveOrphanedAnnotations() = True
Dim oView As DrawingView
oView = ActiveSheet.View("VIEW1").View
oViewf = ActiveSheet.View("FLAT STATE").View
docname=ThisDoc.FileName(False) 'without extension
oView.ActiveMemberName = docname
oViewf.ActiveMemberName = docname

Dim hSheet As Sheet
hSheet = ThisApplication.ActiveDocument.Sheets.Item(1)
ThisApplication.ActiveDocument.SelectSet.Select(hSheet)
'Auto-Reattach Annotation
ThisApplication.CommandManager.ControlDefinitions.Item("DLxAnnoReconnectCmd").Execute
'Auto-Reattach Orphaned Annotations
ThisApplication.CommandManager.ControlDefinitions.Item("DLxAutoReattachSickAnnotationsCmd").Execute

0 Likes
Accepted solutions (1)
4,369 Views
12 Replies
Replies (12)
Message 2 of 13

clutsa
Collaborator
Collaborator

I haven't made a test page to verify this yet but try...

Dim oDraw As DrawingDocument
oDraw = ThisApplication.ActiveDocument
oDraw.DrawingSettings.PreserveOrphanedAnnotations() = True
Dim oView As DrawingView
oView = ActiveSheet.View("VIEW1").View
oViewf = ActiveSheet.View("FLAT STATE").View
docname=ThisDoc.FileName(False) 'without extension
oView.ActiveMemberName = docname
oViewf.ActiveMemberName = docname

Dim hSheet As Sheet
hSheet = ThisApplication.ActiveDocument.Sheets.Item(1)
ThisApplication.ActiveDocument.SelectSet.Select(hSheet)
'Auto-Reattach Annotation
ThisApplication.CommandManager.ControlDefinitions.Item("DLxAnnoReconnectCmd").Execute2(False)
'Auto-Reattach Orphaned Annotations
ThisApplication.CommandManager.ControlDefinitions.Item("DLxAutoReattachSickAnnotationsCmd").Execute2(False)

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 13

briant.markham
Enthusiast
Enthusiast

That didn't work, but I came up with a messy solution about 10 min after my orginal post. Another question though, is there a way to delete an Ilogic rule from a document after it has run, using ilogic? Or better yet, what is the best way to create thousands of ipart/Iassembly drawings where only a couple of things change from a template, my method with the above code works but it still requires me to manually create copies of the drawing file template correctly named and then open the drawing where the ilogic does the ipart/iassembly selection and then save and close the drawing.

0 Likes
Message 4 of 13

clutsa
Collaborator
Collaborator

So you have an iPart/iAssembly Factory and want to make a drawing for each factory member by doing a "save as" of a template and changing the active member?

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 5 of 13

briant.markham
Enthusiast
Enthusiast

Essentially yes, but with a little more automation than that. What I have currently been doing is making a bunch of copies of my drawing template, using a batch file, copying them to the correct filename that matches the member, then I open them all and the ilogic rule "triggers on open" and sets the member/bom/views etc. I give it a glance and save and close. The end result is a drawing for every ipart/iassembly, I don't really care how that result is arrived at, is there a better way to get to that result than what I am doing?

0 Likes
Message 6 of 13

clutsa
Collaborator
Collaborator

 

You could make the changes and then run the save as...

Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument
Dim newDoc As DrawingDocument
Dim model As PartDocument = doc.ReferencedDocuments.Item(1)
Dim factory As PartDocument = model.ReferencedDocuments.Item(1)
Dim member As iPartTableRow
For Each member In factory.ComponentDefinition.iPartFactory.TableRows
	NewFileName = member.Item(1).Value
	ActiveSheet.View("VIEW1").View.ActiveMemberName = NewFileName
	'other code to fix drawings and what not.
	doc.SaveAs(ThisDoc.Path & "\" & NewFileName & ".idw", True)
Next

This is made to only do iParts but I don't think it would take much effort to make a separate code to do iAssemblies. (when you try to make it do both it takes a bit more planning) Really not that different then what you're probably doing.

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 7 of 13

briant.markham
Enthusiast
Enthusiast

That works pretty well except that it compounds any errors when changing out members and fixing orphaned dimensions, so that after about 3 or 4 ipart members the dimensions/annotations  are completely lost. Is there a way to get it to make each new drawing from the orginal unchanged template instead of the last set of changes made to the template?

0 Likes
Message 8 of 13

clutsa
Collaborator
Collaborator
Accepted solution

See how this treats you...

Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument
Dim newDoc As DrawingDocument
Dim model As PartDocument = doc.ReferencedDocuments.Item(1)
Dim factory As PartDocument = model.ReferencedDocuments.Item(1)
Dim member As iPartTableRow
Dim transMgr As TransactionManager = app.TransactionManager
For Each member In factory.ComponentDefinition.iPartFactory.TableRows
	Dim trans As Transaction = transMgr.StartTransaction(ThisDoc.Document, "UpdateTemplate")
	NewFileName = member.Item(1).Value
	ActiveSheet.View("VIEW1").View.ActiveMemberName = NewFileName
	'other code to fix balloons and what not.
	doc.SaveAs(ThisDoc.Path & "\" & NewFileName & ".idw", True)
	trans.End
	app.CommandManager.ControlDefinitions("appUndoCmd").Execute
Next

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 9 of 13

briant.markham
Enthusiast
Enthusiast

Thanks, you are genius, that with a couple of tweaks is absolutely perfect. What is a good resource for getting better at this kind of programming?

0 Likes
Message 10 of 13

clutsa
Collaborator
Collaborator

I've found tons of useful info in the forums of course. It's my go to, but I have also used...

http://modthemachine.typepad.com/ not always the easiest to find what you're looking for but very well explained examples.

http://adndevblog.typepad.com/ much like the blog above but a much broader topic range.

https://www.youtube.com/channel/UCF7zEkelSRiHB1rOnspaBgQ This "TFI" fellow has some good videos if that's your thing. If it's they guy I think it is, he's possibly a little crazy, but that makes him interesting. 

Just a plain goggle search can be good.

Last but not least just keep scrapping things together. The more you make, even if made poorly, will expose you to more and better ways of doing things. I've never taken a course on programming. I learned by doing... and breaking. I take a working piece of code and change one thing and see how that changes what it does. Sometimes it does what I expect, sometimes not. I keep playing with it until I can product what will happen. Then I know I have an actual understanding of what it's doing and how it works. 

Of course there are a ton more good resources out there. This is just a start.

 

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 11 of 13

briant.markham
Enthusiast
Enthusiast

TFI is definitly a character. What do I have to do to get it working for iassemblies? I tried this and got this error

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.AssemblyDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D465-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

SyntaxEditor Code Snippet

Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument
Dim newDoc As DrawingDocument
Dim model As AssemblyDocument = doc.ReferencedDocuments.Item(1)
Dim factory As AssemblyDocument = model.ReferencedDocuments.Item(1)
Dim member As iAssemblyTableRow
Dim transMgr As TransactionManager = app.TransactionManager
For Each member In factory.ComponentDefinition.iAssemblyFactory.TableRows
	Dim trans As Transaction = transMgr.StartTransaction(ThisDoc.Document, "UpdateTemplate")
	NewFileName = member.Item(1).Value
	ActiveSheet.View("VIEW1").View.ActiveMemberName = NewFileName
	Dim oCurrentSheet As Sheet = ThisDoc.Document.ActiveSheet
	Dim oDwgViews As DrawingViews
	oDwgViews = oCurrentSheet.DrawingViews
		For Each oView In oDwgViews
		        Do While oView.IsUpdateComplete = False
		        ThisApplication.UserInterfaceManager.DoEvents
		        ThisApplication.StatusBarText = "Updating drawing views..."
		        Loop
	    Next
	'Auto-Reattach Annotation
	ThisApplication.CommandManager.ControlDefinitions.Item("DLxAnnoReconnectCmd").Execute
	'Auto-Reattach Orphaned Annotations
	ThisApplication.CommandManager.ControlDefinitions.Item("DLxAutoReattachSickAnnotationsCmd").Execute
	doc.SaveAsInventorDWG(ThisDoc.Path & "\" & NewFileName & ".dwg", True)

	trans.End
	app.CommandManager.ControlDefinitions("appUndoCmd").Execute
Next

 

0 Likes
Message 12 of 13

clutsa
Collaborator
Collaborator

I don't know if you need to go through the "model" to get to an iAssemblyFactory...

Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument
Dim newDoc As DrawingDocument
'Dim model As AssemblyDocument = doc.ReferencedDocuments.Item(1)
Dim factory As AssemblyDocument = doc.ReferencedDocuments.Item(1) 
Dim member As iAssemblyTableRow
Dim transMgr As TransactionManager = app.TransactionManager
For Each member In factory.ComponentDefinition.iAssemblyFactory.TableRows
	Dim trans As Transaction = transMgr.StartTransaction(ThisDoc.Document, "UpdateTemplate")
	NewFileName = member.Item(1).Value
	ActiveSheet.View("VIEW1").View.ActiveMemberName = NewFileName
	Dim oCurrentSheet As Sheet = ThisDoc.Document.ActiveSheet
	Dim oDwgViews As DrawingViews
	oDwgViews = oCurrentSheet.DrawingViews
		For Each oView In oDwgViews
		        Do While oView.IsUpdateComplete = False
		        ThisApplication.UserInterfaceManager.DoEvents
		        ThisApplication.StatusBarText = "Updating drawing views..."
		        Loop
	    Next
	'Auto-Reattach Annotation
	ThisApplication.CommandManager.ControlDefinitions.Item("DLxAnnoReconnectCmd").Execute
	'Auto-Reattach Orphaned Annotations
	ThisApplication.CommandManager.ControlDefinitions.Item("DLxAutoReattachSickAnnotationsCmd").Execute
	doc.SaveAsInventorDWG(ThisDoc.Path & "\" & NewFileName & ".dwg", True)

	trans.End
	app.CommandManager.ControlDefinitions("appUndoCmd").Execute
Next

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 13 of 13

briant.markham
Enthusiast
Enthusiast

That worked great for the regular iassembly, but of course the very next iassembly I needed to do was an Weldment Iassembly. I was trying to adapt it this, and it is something close to this.

SyntaxEditor Code Snippet

Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument
Dim newDoc As DrawingDocument
'Dim model As AssemblyDocument = doc.ReferencedDocuments.Item(1)
Dim factory As AssemblyDocument = doc.ReferencedDocuments.Item(1) 
Dim member As iAssemblyTableCell
Dim transMgr As TransactionManager = app.TransactionManager
Dim compDef As AssemblyComponentDefinition = factory.ComponentDefinitions.Item(1)


For Each member In compDef.iAssemblyMember.Row.Item()
	Dim trans As Transaction = transMgr.StartTransaction(ThisDoc.Document, "UpdateTemplate")
	NewFileName = member.Item(1).Value
	docnamearr = New String() {NewFileName}
	ActiveSheet.View("VIEW1").View.ActiveMemberName = NewFileName
	doc.ActiveSheet.PartsLists.Item(1).MembersToInclude() = docnamearr
	
	Dim oCurrentSheet As Sheet = ThisDoc.Document.ActiveSheet
	Dim oDwgViews As DrawingViews
	oDwgViews = oCurrentSheet.DrawingViews
		For Each oView In oDwgViews
		        Do While oView.IsUpdateComplete = False
		        ThisApplication.UserInterfaceManager.DoEvents
		        ThisApplication.StatusBarText = "Updating drawing views..."
		        Loop
	    Next
	Dim hSheet As Sheet
	hSheet = ThisApplication.ActiveDocument.Sheets.Item(1)	
	'Auto-Reattach Annotation
	ThisApplication.CommandManager.ControlDefinitions.Item("DLxAnnoReconnectCmd").Execute
	'Auto-Reattach Orphaned Annotations
	ThisApplication.CommandManager.ControlDefinitions.Item("DLxAutoReattachSickAnnotationsCmd").Execute
	doc.SaveAsInventorDWG(ThisDoc.Path & "\" & NewFileName & ".dwg", True)

	trans.End
	app.CommandManager.ControlDefinitions("appUndoCmd").Execute
Next

 

0 Likes