iLogic that can change userparameters in assembly document driven by a part document

iLogic that can change userparameters in assembly document driven by a part document

raymaster
Contributor Contributor
1,069 Views
6 Replies
Message 1 of 7

iLogic that can change userparameters in assembly document driven by a part document

raymaster
Contributor
Contributor

Hello, and happy new year.

 

I created an assembly that is driven by a part document, so I need an iLogic that can change userparameters in the assembly " length and width " then creates a new model state on both sides of the part doument and the assembly document.

 

so lets say I have an assembly with 4 components, I need to change their width and length or position then send a new model state to the IPT files and creates a new one at the assembly side.

 

I need:

 

1. to share parameters across all components

2. create model states in the part documents and in the assembly 

3. control the parameters of the parts from the assembly using forms

 

I'll be glad for an iLogic API explaination of how to do that.

 

Best

0 Likes
1,070 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @raymaster.  First of all, if the parameters within the assembly are being 'driven' by a part, then you will not be able to control those parameters from the assembly.  They will be greyed out, or ReadOnly on the assembly side.  You would have to make any changes to those parameters on the part side.  And trying to use an iLogic form from the assembly to control the parameters in the part will not work either.  There are two types of iLogic Forms...internal (saved within an Inventor document), and global (its specification is saved within an external XML file, along with other global form specifications).  When you launch an internal iLogic rule, it will remain focused on the document that it is saved within, but if that form is saved within the part, and you have the assembly currently on your screen, you may not be able to launch that form that is in the part.  Then, if you use a global iLogic form, these will focus on whichever Inventor document that was actively showing on the screen when it was first launched, and will not change its focus to another document just because you make some other document active while the form is open.  So if you launched a global form while the assembly was active, the focus of that form will be on the assembly, not the part.

 

As for the ModelStates, that may be possible, but if it were possible, but I have not tried 'Linking' parameters from a part with multiple ModelStates to an assembly that the part will be a component in, and do not know what effect changing between ModelStates in the part would have on the assembly.  Multiple ModelStates is like multiple Documents within a single File on disk, so it seems to me like simply changing which ModelState is active in the part would not effect the parameter values in the assembly, because it seems like the 'Link' itself would have to be changed to do that, because the link is to the parameters in a specific document.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

raymaster
Contributor
Contributor

Thanks for the reply.

 

Actually I managed to do that back and forth parameters change and it worked, but I need to do this for multi components not for one, here is the code "relevant to my project" :

Sub main
Dim oInvApp As Inventor.Application = ThisApplication
Dim oDoc As AssemblyDocument = oInvApp.ActiveDocument
Dim oAllRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oDocParams As UserParameters = oDef.Parameters.UserParameters
Dim dWid, dSide As Double
Dim bAnchLeft, bAnchRight, bCutLeft, bCutBott, bCutRight As Boolean
Dim sNameModel As String
Try : dWid = oDocParams("dWidth").Value : Catch : Exit Sub : End Try
Try : dHeig = oDocParams("dHeight").Value : Catch : Exit Sub : End Try
Try : bAnchLeft = oDocParams("b_AnchorLeft").Value : Catch : Exit Sub : End Try
Try : bAnchRight = oDocParams("b_AnchorRight").Value : Catch : Exit Sub : End Try
Try : sNameModel = oDocParams("sName").Value : Catch : Exit Sub : End Try
Try : bCutLeft = oDocParams("b_CutSargelLeft").Value : Catch : Exit Sub : End Try
Try : bCutBott = oDocParams("b_CutSargelBottom").Value : Catch : Exit Sub : End Try
Try : bCutRight = oDocParams("b_CutSargelRight").Value : Catch : Exit Sub : End Try
Dim oOccs As ComponentOccurrences = oDef.Occurrences
Dim oMasterDoc As PartDocument = oOccs(1).Definition.Document
Dim oOpenDoc As PartDocument = oInvApp.Documents.Open(oMasterDoc.FullDocumentName, False)
Dim oOpenDef As PartComponentDefinition = oOpenDoc.ComponentDefinition
Dim oMasterParams As UserParameters = oOpenDef.Parameters.UserParameters
Dim oMasterStates As ModelStates = oOpenDef.ModelStates
If Not String.IsNullOrEmpty(sNameModel) Then
Try : oMasterStates(sNameModel).Activate()
Catch : oMasterStates.Add(sNameModel).Activate() : End Try
End If
oMasterStates.MemberEditScope = MemberEditScopeEnum.kEditActiveMember
Dim oFrontMaster, oSideMaster, oHeightMaster As UserParameter
Try : oHigMaster = oMasterParams("dHeight") : Catch : Exit Sub : End Try
Try : oWidMaster = oMasterParams("dWidth") : Catch : Exit Sub : End Try
oWidMaster.Value = dWid
oHigMaster.Value = dHeig
For Each oFeat As PartFeature In oOpenDef.Features
Select Case oFeat.Name
Case "Left_Profile" : oFeat.Suppressed = bAnchLeft
Case "LeftProfile_Cut" : oFeat.Suppressed = bAnchLeft
Case "Right_Profile" : oFeat.Suppressed = bAnchRight
Case "RightProfile_Cut" : oFeat.Suppressed = bAnchRight
Case "Profile_Side_Left" : oFeat.Suppressed = bAnchLeft
Case "Left_Profile_Anchor" : oFeat.Suppressed = Not bAnchLeft
Case "LeftProfileAnchor_Cut" : oFeat.Suppressed = Not bAnchLeft
Case "Right_Profile_Anchor" : oFeat.Suppressed = Not bAnchRight
Case "RightProfileAnchor_Cut" : oFeat.Suppressed = Not bAnchRight
Case "Cut_Top_Left_Anchor" : oFeat.Suppressed = bAnchLeft
Case "Cut_Top_Right_Anchor" : oFeat.Suppressed = bAnchRight
Case "Cut_Bottom_Left_Anchor" : oFeat.Suppressed = bAnchLeft
Case "Cut_Bottom_Right_Anchor" : oFeat.Suppressed = bAnchRight
Case "Holes_Left_NotAnchor" : oFeat.Suppressed = bAnchLeft
Case "Holes_Right_NotAnchor" : oFeat.Suppressed = bAnchRight
Case "Holes_Left_Anchor" : oFeat.Suppressed = Not bAnchLeft
Case "Holes_Right_Anchor" : oFeat.Suppressed = Not bAnchRight

End Select
Next
Dim oModelDoc As ModelStates = oDef.ModelStates
If Not String.IsNullOrEmpty(sNameModel) Then
Try : oModelDoc(sNameModel).Activate()
Catch : oModelDoc.Add(sNameModel).Activate() : End Try
End If

End Sub
 
0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

OK.  I assumed that you had actually Linked the parameters from a part to the assembly, then I assumed that you wanted to also Link the parameters from either that same part, or from the assembly, to all other components in your assembly.  I did not think you meant that you just wanted to fully control it all through iLogic rule codes.  If that is the case, then that would certainly be possible.  Your code looks OK so far, but it looks like you could be looping through the components in the assembly, instead of just specifying the first one by its Index number.  I saw where you got a reference to all the referenced documents of the main assembly, but then you are not really using that collection anywhere after that point.  I'm not sure which would be better though...iterating through the components, or iterating through the referenced documents.  Usually iterating through the referenced documents is more efficient, but since you are creating a new ModelState within those referenced documents, I am not sure if it is you design intent to then set the component in the assembly to that new ModelState.  If that is the case, then you may want to iterate the components, that way you have a reference to each component, so that you can change the ModelState that the component is set to within the assembly.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

raymaster
Contributor
Contributor

Thanx for the reply

 

So assume you have two boxes in an assembly, as each box has one hole
while W01 & L01 & H01 are the dimensions of the first box, and W02 & L02 & H02 are the dimensions of the second box

Kindly try to write a simple code that can do the following:

 

1. control the dimensions of each box or one at least

2. create a model state with a new name on both part and assembly documents

3. control suppression of the middle hole

4. update the documents and activate the modelstate

 

Thank you in advance

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

What you described sounds like something that can be mostly done without even needing any iLogic code to control, if there are a set number of size variations, and hole suppression statuses.  Within each of the unique part files, create a ModelState for each size/hole suppression variation.  While each ModelState is active, set the parameter values to what you want for that size variation, and set the hole suppression the way you want it for that variation.  Then in the assembly create ModelStates with the same exact names as the ones you created in the parts.  Then, while the main assembly is active, you can use a built-in tool to link the ModelStates between the main assembly and any top level components that have ModelStates with those same names.  Then when you change which ModelState is active in the assembly, that will trigger a reaction that will go through all top level components, and if they have a ModelState with the same name available, it will set that component to that ModelState also.  That built-in tool is on the Assemble tab, within the Productivity panel, within the drop-down list, called "Link Model States".  You would just want to make sure that the names of the ModelStates in the parts match the names of the ModelStates in the assembly.  Then you can easily switch the configuration of the assembly by changing which ModelState is active in the main assembly, and everything else will change automatically, without needing any iLogic code.

WCrihfield_0-1704297867867.png

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

raymaster
Contributor
Contributor

Thanx for the reply

 

no thats cant be done by linking, as I need to produce new modelstates in the assembly, then send them to the files, so I dont have pre created modelstates in the part files.

 

If I had all the model states set on all parts, so I can use the spreadsheet to link and change model states.

 

wish you got my point.

 

anyhow I need to control this thing by iLogic rules and Forms.

 

Thanx

0 Likes