Constraining Tube and Pipe Runs To Main Assembly Workflow

Constraining Tube and Pipe Runs To Main Assembly Workflow

A.Acheson
Mentor Mentor
2,137 Views
2 Replies
Message 1 of 3

Constraining Tube and Pipe Runs To Main Assembly Workflow

A.Acheson
Mentor
Mentor

Hi all,

 

Long time forum user, first time poster. I would just like to say a big thank you to all the forum users out there especially the professionals who make everything  possible.

 @salariua,@cbenner@Curtis_Waguespack , @WCrihfield , @JhoelForshav@JBerns to name just a few. 

I have referenced the source code as much as possible as I am certainly not the creator but I hope to improve my skills over time. So please forgive me in advance if the coding layout is poor or the language is incorrect. I know T&P content is limited on here due to it not being fully supported in the API. However I just want to post a work around I think might work for those familiar with T&P quirks. 

 

The main one being if you do not constrain the origins of the main T&P  and then the subsequent runs it can develop into a nightmare later. Manually constraining  the origin planes is time consuming and certainly tiring So attached is the workflow in .txt files. Create these as external rules and place the rules in a user form. 

 

Workflow, 

1.Start:

T&P module is started, if the main assembly has not been saved since creation user is prompted to do so, Module is created and first run is created, T&P assembly is opened in it's own assembly and user is prompted to constrain the first run. Assembly closes and returns to main assembly.

 

2.Run Constrain Manual:

Optional

Run this rule  to constrain Main T&P assembly to Main Assembly  origin,  depending on desired location 

 

3.Run Constrain Auto:

T&P assembly is opened in it's own assembly and user is prompted to constrain the a run. Assembly closes and returns to main assembly.

4.New Run:

This rule is to follow, Create new run and repeat step 3 and ends with new run active. 

5.BOM Sort:

This rule is to follow. Uses similar method to step 3 in order to sort T&P  and run  BOM. BOM is then organized when parts list is created in the drawing.. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Accepted solutions (1)
2,138 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

Attached are screenshot of workflow and New Run Rule

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 3

A.Acheson
Mentor
Mentor

Here is an update to the original rules to constrain tube and pipe assemblies (2-3). The previous versions involved opening the main tube and pipe document and then the user manually selecting the runs to constrain. The rule below will both constrain Tube and Pipe Top Level (TPAssy) to Main Assembly and constrain any Runs that are not yet constrained to TPAssy. It will bypass any run copies as these would normally be constrained individually by the user. It is more efficient and hopefully will help somebody out. 

 

Checking for the copies of runs and filtering them out by using  the boolean occurrence.adaptive failed to work as it does not seem to be correctly returning the desired result when used in TPAssy. Instead I turned to using a custom  function CheckNode to look for the presences of the make adaptive button  in the right click context menu.

 

Constraints rule adapted from this post. Thanks to all involved. 
'https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/inventor-api-sub-assembly-constraints-to-master-assembly/td-p/6257598
Sub Main() Dim oAssyDoc As AssemblyDocument oAssyDoc = ThisApplication.ActiveDocument'Get the active document. 'Set Component Definition Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = oAssyDoc.ComponentDefinition 'This is the Overall Assembly We're In Dim oOccCol As New Collection 'Create a collection to store the occurrences we want to work with Dim oOcc As ComponentOccurrence For Each oOcc In oAsmCompDef.Occurrences 'Iterate through all of the occurrences at Level 1 Dim oOccDoc As Document oOccDoc = oOcc.Definition.Document Dim bIsTPAssyDoc As Boolean bIsTPAssyDoc = oOccDoc.DocumentInterests.HasInterest("Piping Runs Environment")'Get Tube and Pipe Top Level(TPAssy) If bIsTPAssyDoc = True Then oOcc.Edit 'Activate TPAssy to ensure check for copies function works consistently oOccCol.Clear oOccCol.Add(oOcc) If oOcc.Constraints.Count < 1 Then 'Check that no constrain allready exists Constrain(oOccCol, oAsmCompDef)'Constrain individual Run to TPAssy End If Dim TotSubAssemblyOccurences As Integer TotSubAssemblyOccurences = oOcc.SubOccurrences.Count'Get the Total # of Sub-Assemblies in Active Doc Dim SubCount As Integer For SubCount = 1 To TotSubAssemblyOccurences 'For Each Sub Assembly If oOcc.SubOccurrences.Item(SubCount).DefinitionDocumentType = kAssemblyDocumentObject Then If oOcc.SubOccurrences.Item(SubCount).Constraints.Count < 1 Then 'Check that no constrain allready exists 'AndAlso Dim CopyCheck As Boolean CopyCheck = CheckNode(oOcc.SubOccurrences.Item(SubCount))' Function to check if run is a copy. If CopyCheck = False Then 'If not a copy then continue to process constraints oOccCol.Clear oOccCol.Add(oOcc.SubOccurrences.Item(SubCount)) 'Add run occurrence to the collection Constrain(oOccCol, oOcc.Definition)'Constrain individual Run to TPAssy End If End If End If Next End If Next MessageBox.Show("Constraints Completed", "iLogic") End Sub Private Function CheckNode(oOccurrence As ComponentOccurrence)'Check each browser node and look for adaptive enabled status. If enable this is a copy of a run Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition oDef = oDoc.ComponentDefinition Dim oPane As BrowserPane oPane = oDoc.BrowserPanes.ActivePane Dim oOcc As ComponentOccurrence Dim oNode As BrowserNode oNode = oPane.GetBrowserNodeFromObject(oOccurrence) oNode.DoSelect ' Select browser node Dim cd As ControlDefinition cd = ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyAdaptiveCtxCmd")'Mimics right clicking on selected node and looking at adaptive command Dim Ans As Boolean 'Check status of this command Ans = cd.Enabled oDoc.SelectSet.Clear 'Clear selection Return Ans End Function Private Sub Constrain(oOccurrences As Collection ,oAsmDef As AssemblyComponentDefinition) ' Get the planes from the base (Master Assembly)part Dim BaseYZ As WorkPlane Dim BaseXZ As WorkPlane Dim BaseXY As WorkPlane BaseYZ = oAsmDef.WorkPlanes.Item(1) BaseXZ = oAsmDef.WorkPlanes.Item(2) BaseXY = oAsmDef.WorkPlanes.Item(3) 'Define Constraints Dim Constraints As AssemblyConstraints Constraints = oAsmDef.Constraints ' Iterate through the list of occurrences Dim i As Integer For i = 1 To oOccurrences.Count 'Start with the first occurence Dim thisOcc As ComponentOccurrence thisOcc = oOccurrences.Item(i) ' Get the planes from the occurrence Dim occPlaneYZ As WorkPlane Dim occPlaneXZ As WorkPlane Dim occPlaneXY As WorkPlane Call GetPlanes(thisOcc, occPlaneYZ, occPlaneXZ, occPlaneXY) ' Add the flush constraints. Call Constraints.AddFlushConstraint(BaseYZ, occPlaneYZ, 0) Call Constraints.AddFlushConstraint(BaseXZ, occPlaneXZ, 0) Call Constraints.AddFlushConstraint(BaseXY, occPlaneXY, 0) Next ' Occurrence i.e. sub-assembly End Sub '[Planes ' Utility function used by the AlignOccurrencesWithConstraints macro. ' Given an occurrence it returns the base work planes that are in ' the part or assembly the occurrence references. It gets the ' proxies for the planes since it needs the work planes in the ' context of the assembly and not in the part or assembly document ' where they actually exist. Private Sub GetPlanes(ByVal Occurrence As ComponentOccurrence, _ ByRef BaseYZ As WorkPlane, _ ByRef BaseXZ As WorkPlane, _ ByRef BaseXY As WorkPlane) ' Get the work planes from the definition of the occurrence. ' These will be in the context of the part or subassembly, not ' the top-level assembly, which is what we need to return. BaseYZ = Occurrence.Definition.WorkPlanes.Item(1) BaseXZ = Occurrence.Definition.WorkPlanes.Item(2) BaseXY = Occurrence.Definition.WorkPlanes.Item(3) ' Create proxies for these planes. This will act as the work ' plane in the context of the top-level assembly. Call Occurrence.CreateGeometryProxy(BaseYZ, BaseYZ) Call Occurrence.CreateGeometryProxy(BaseXZ, BaseXZ) Call Occurrence.CreateGeometryProxy(BaseXY, BaseXY) End Sub ']

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes