Place assembly and display its form

Place assembly and display its form

Damian_Apex
Enthusiast Enthusiast
387 Views
3 Replies
Message 1 of 4

Place assembly and display its form

Damian_Apex
Enthusiast
Enthusiast

Hi, 

I want a program that will add my assembly from a defined location and after placing it (this is working in my code), it will show me the form of newly added assembly.

 

I don't know if it's possible but it will be great if program will stop after this line:

ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute	

and after user will place it, form ("FORM1") will popup

 

 

Sub main

Dim Path As String = ThisDoc.Path & "\"
Dim AssyDoc As Document = ThisApplication.Documents.Open("D:\3_TEST\ACCESSDOOR\CUSTOM.iam", False)

ProjectNo = InputBox("Project Number", "iLogic", "000")
AssyDoc.SaveAs(Path & ProjectNo & "-ASSEMBLY-" & ".iam", False)

For Each oDoc In AssyDoc.AllReferencedDocuments 'loop through all part in assembly	

	TAG_NO = InputBox("TAG", "iLogic", "001")
	oDoc.SaveAs(Path & ProjectNo & "item-" & TAG_NO & ".ipt", False)

Next

Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Call oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(50, 50, 50), True)

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, AssyDoc.FullDocumentName) 
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute	

ThisApplication.Documents.Open(AssyDoc.FullDocumentName, False)

Trace.Write(AssyDoc.FullDocumentName)
iLogicForm.Show("FORM1")
End Sub 

 

 

0 Likes
Accepted solutions (1)
388 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Damian_Apex.  The problem with that 'iLogicForm.Show("Form1")' iLogic snippet, is that there appears to be no documentation about which document it is designed to target by default, and apparently no way to tell it to target a specific document.  So, in an assembly scenario, where there are multiple documents open, and/or from an external iLogic rule, this confusion can be even more prevalent.

Here is a bit of exploratory code I created at some point that checks which iLogic Forms are available using those snippets:

Dim oLocalFormNames = iLogicForm.FormNames
If oLocalFormNames.Count = 0 Then
	MsgBox("There were no 'Local' iLogic Forms.", , "")
Else
	a = InputListBox("", oLocalFormNames,"", "Local Form Names")
End If
Dim oGlobalFormNames = iLogicForm.GlobalFormNames
If oGlobalFormNames.Count = 0 Then
	MsgBox("There were no 'Global' iLogic Forms.", , "")
Else
	b = InputListBox("", oGlobalFormNames,"", "Global Form Names")
End If

There is something I saw recently that might be able to help here though if your version of Inventor is new enough.  It makes use of the StandardObjectFactory.Create() method (only available within iLogic).  This allows you to specify a Document object, and can use the resulting IStandardObjectProvider to initiate most other iLogic only tools, one of which is the iLogicForm.  My understanding is that if you access the iLogicForm object from that IStandardObjectProvider object you created, it will target the document you specified when you created it.  Using it would look something like this:

Dim oTargetDocument As Document = ThisApplication.Documents.ItemByName("C:\Temp\MyAssembly.iam")
SOP = StandardObjectFactory.Create(oTargetDocument)
SOP.iLogicForm.Show("Form1")

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

Damian_Apex
Enthusiast
Enthusiast

Thank you, the second part is really helpful.

 

It's possible to stop program while the item is placed ? 

ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute

 

 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @Damian_Apex.  Of the two different Execute methods (Execute & Execute2), Execute2 offers more control (synchronous or asynchronous execution).  But I doubt either option will help here.  There is not a really good option in simple iLogic terms to make it intelligently wait for you to be done with placing the component, before resuming.  There are some general vb.net methods out there (Process.WaitForExit, Task.Wait, Thread.Sleep, etc.), but I don't know of a specific one that would work in this situation as you are wanting it to (without a ton of extra code).  Why don't you just use one of the normal API methods (such as the ones defined under the ComponentOccurrences object) to add the component to the assembly, instead of executing the command for the manual process?  That would eliminate the need to pause the code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)