Calling Local Form Part From Assembly

Calling Local Form Part From Assembly

drafter_sby2
Contributor Contributor
533 Views
5 Replies
Message 1 of 6

Calling Local Form Part From Assembly

drafter_sby2
Contributor
Contributor

Hi All,.. 

I want an Asking Few Question. 

1. Can We Do "Call Local Form a Part From Assembly in I-Logic" ??

2. Its Possible Or Not?

3. Where I get A Xample Code or Tutorial?

 

 

 

0 Likes
Accepted solutions (2)
534 Views
5 Replies
Replies (5)
Message 2 of 6

Andrii_Humeniuk
Advisor
Advisor

Hi @drafter_sby2 . If I understand correctly, you want to run a local form from the part in assembly. Yes it is possible, you can see a sample code in this video.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 6

drafter_sby2
Contributor
Contributor

Correct,...

If I Resume the workflow of the video example Code.

The Code in Assembly, Calling Local rule from The Part Or Sub-Assembly, Which Part Selected.

Where is the Local rule Calling to Open Local Form The Part Or Sub-Assembly.

*Be care full  ***Form***&***From***

 

Sorry, My Next Question. 

If I have Just Only 1 Form. In-Sub Assembly or Part but Potential with Deferent Name. If I work in Assembly Which have Many Sub Assembly or Part. 

should I Add a Rule Named "Show Form" in Each Part or Each Sub-Assembly To Open Form in Assembly?  

 

I Drop The Example Video Code

 

'Check Whether Open Document is an assembly And Exit Rule If Not
oDoc = ThisDoc.ModelDocument
If oDoc.DocumentType = kPartDocumentObject Then
MessageBox.Show ("This rule can only be run in an assembly file - exiting rule", "Excitech i-Logic")
Return
End If

Dim targetOcc As ComponentOccurrence = Nothing
Do While True
	targetOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Sub-Assembly Or Part to Modify... (Press ESC to Cancel)")
	If Not targetOcc Is Nothing Then
		Exit Do
	else
		Dim Res As MsgBoxResult = MsgBox("No Sub-Assembly Selected - Exit?",36, "Excitech i-Logic")
		If Res = vbYes Then
			Return
		Else
			'Do Nothing-Keep On Looping
		End If
	End If
Loop

Try
iLogicVb.RunRule(targetOcc.Name, "Show Form") 'Show Form is Your rule in Part to Open Form Part or Sub-Assembly
Catch
MessageBox.Show ("There needs to be a rule called 'Show Form' in the Part Or Sub-Assembly to Run Their Local Form", "Excitech i-Logic")
End Try

 

 

0 Likes
Message 4 of 6

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Yes, you must add the iLogic "Show Form" rule to your subcomponents to trigger the form in the main assembly. This rule can activate a rule in subcomponents, which in turn shows your form.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 5 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi guys.  Not sure how you may need to make this happen as far as any further automation plans go, but there may be another, more direct way.  Since around Inventor 2021 or so, we can use an iLogic tool that will allow us to initialize many of the common iLogic API code snippets with an actual Document object for them to be referencing, to help clarify which document they will be focused on.

StandardObjectFactory Class 

StandardObjectFactory.Create Method 

IStandardObjectProvider Interface 

Review the following iLogic rule code example, to try it out.  The first couple lines let you manually select an assembly component, and if none was selected, it will exit the rule.  If one was selected, it attempts to get the Document object that the assembly component is referencing, so that we can access the internal iLogic Form within it.  Once it has the Document, it uses the create object provider method to create an object provider, with that Document as input (specified which document it should focus on).  Then it uses that provider to show the internal iLogic form within that document.  However, you will need to change "Form 1" to the actual name of the form within that document.

Dim oOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Component - or press ESC key to quit.")
If oOcc Is Nothing Then Return 'Return means exit this code routine
Dim oOccDoc As Document = oOcc.ReferencedDocumentDescriptor.ReferencedDocument
Dim SOP As IStandardObjectProvider = iLogicVb.CreateObjectProvider(oOccDoc)
SOP.iLogicForm.Show("Form 1", FormMode.Modal)

If the name of the form changes, then you will likely need a more complex code solution which will be able to find the form by some other means than by its name.  If there is only one form in the document, then there is actually still a way to do that without getting super complicated.  Something like the following maybe.

Dim oOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Component - or press ESC key to quit.")
If oOcc Is Nothing Then Return 'Return means exit this code routine
Dim oOccDoc As Document = oOcc.ReferencedDocumentDescriptor.ReferencedDocument
Dim SOP As IStandardObjectProvider = iLogicVb.CreateObjectProvider(oOccDoc)
Dim oFormNames As IEnumerable(Of String) = SOP.iLogicForm.FormNames
If oFormNames IsNot Nothing Then
	Dim sFormName As String = oFormNames.ElementAt(0)
	SOP.iLogicForm.Show(sFormName, FormMode.Modal)
End If

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6

drafter_sby2
Contributor
Contributor

@Andrii_Humeniuk, yes Its Totaly Works on me.

@WCrihfield, Hi Sir. I Will Tray Your Code First...

I Have Idea that.

May be Or Potential. If it Works, can Put Form from Sub-Assembly or Part in First Form with Different name. it can Be default Add Ins I think. 

 

0 Likes