Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Counting parts and renaming in an assembly using Ilogic

5 REPLIES 5
Reply
Message 1 of 6
stephanbotes
1335 Views, 5 Replies

Counting parts and renaming in an assembly using Ilogic

I have just recently started get my feet wet using ilogic to control various aspects of my assemblies. in particular i have been using ilogic rules to layout crossmembers in a semi-trailer (i.e. essentially a very large ladder frame) 

The challenging aspect of the layout is that the spacing of crossmembers needs to vary based on subframe length, and a couple other constraints. this result in a couple individual crossmembers at fixed spacings and most of the rest in three seperate rectangular patterns that can vary in number and spacing. the issue with this is that each crossmember gets numbered almost arbritraily making it difficult to keep track of the order they are in when trying to prepare drawings reflecting the effects of weldment preparations on each crossmembers (each crossmember is affected differently by cutouts for conduit runs contrained within the larger assembly) 

 

what i think is the solution to this is use ilogic to itirate through the assembly and and find each instance of the crossmember assembly and change its name within the toplevel assembly (eg crossmember #1,crossmember #2 etc) based on where it is found. the first one always being fixed it is easy to name but all the other names would depend on first finding all the instances 

 

not sure if this question is clear or not but i would appreciate any help one the ilogic geniuses could give on this.

i have a zip file with the platform.iam assembly in it so one can get a better understanding of what im trying to explain linked on googledrive

 

 

5 REPLIES 5
Message 2 of 6
mrattray
in reply to: stephanbotes

What naming convention do you want your parts to follow?

Mike (not Matt) Rattray

Message 3 of 6
stephanbotes
in reply to: mrattray

at this point any sort of numbering scheme. im thinking from front to back crossmember #1, crossmember #2, etc 

 

havent quite got around to a comprehensive part numbering scheme yet which is one of the next things on the priority list (small company so production takes precedent over standardization, would love to get there eventually which is partly why im trying to make my designs dynamic using ilogic so that a numbering scheme can be automatically implemented rather than having to manually keep track of that...) . if you have ideas in that regard im open for advice.

Message 4 of 6
Anonymous
in reply to: stephanbotes

I’m not 100% sure what you are asking but I would suggest putting a “True/False User Parameter” in all the parts you want to be identified. Have the “True/False User Parameter” be driven by whatever parameters you want.

 

By using code you can search all parts in the assembly for the “True/False User Parameter”. Using If statements, if true you can make it rename the name in the drawing browser bar to anything you want.

 

The code below is searching all parts in an assembly for a custom iproperty “Fluid Mass” and adds them together.  You and tweak the code to look for your “True/False User Parameter”.

 

 

 

Option Explicit

Imports Autodesk.Inventor

 

Sub Main
  Dim oApp As Inventor.Application =  ThisApplication
  Dim oAssy As Inventor.AssemblyDocument = oApp.ActiveDocument
  Dim TotalFluidMass As Double = 0
 
  For Each oSubDoc as Inventor.Document in oAssy.AllReferencedDocuments
    ' Only process if document is a part document
    if oSubDoc.DocumentType = kPartDocument then
       
'Get Custom Properties (User Defined Properties)

        Dim oPartPropset As Inventor.PropertySet = oSubDoc.PropertySets("Inventor User Defined Properties")


       Try 
          Dim FluidMass As Double = oPartPropset("Fluid Mass
").Value
          ' Add part Fluid Mass to total Mass
         TotalFluidMass += FluidMass
       Catch ee As Exception
         ' Do not raise or display an error.  We assume all parts have a "Fluid Mass" custom property
       End Try
    End If
  Next

  ' Get Master Assembly Custom PropertySet

  Dim oAssyPropset As Inventor.PropertySet = oAssy.PropertySets("Inventor User Defined Properties")


  Try
    ' Set Custom Property to total Mass
    oAssyPropset("Total Fluid Mass").Value = TotalFluidMass
  Catch
    ' Do not raise or display an error.  We assume the Master Assembly has  a "Total Fluid Mass" custom property
  End Try

  oAssyPropset = Nothing
  oAssy = Nothing
  oApp = Nothing

 

'Remove the following when doen testing
MessageBox.show(TotalFluidMass.ToString & " TotalFluidMass of parts in the assembly")

 


End Sub

 

 

 

 

I Hope this helps

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

Message 5 of 6
stephanbotes
in reply to: Anonymous

so instead of the true/false parameter could i use the filenames of the parts or the part num property to decide if they are of the right kind?

also would you have a code snippet for changing the name of a part/subassembly in the upper level assembly?

 

reading through your code what i think im still missing is how to identify where each of the crossmembers are positioned within their respective rectangular patterns so that the crossmembers can be sequentially named in the upper level assembly (platform.iam)

Message 6 of 6
Anonymous
in reply to: stephanbotes

Instead of using a “true/false Parameter” you can use a “number Parameter”. The reason I suggested using a Parameter is that it can be driven to say whatever numbers you want by using equations. The “number Parameter” then can drive the number sequences from the Parameter number.

 

Here is an ilogic rule that automatically renames the browser nodes based on part number. This can be tweaked to drive name in sequence from your Parameter number. I found it in this post. http://forums.autodesk.com/t5/Inventor-Customization/Using-iLogic-to-Rename-Browser-Nodes/td-p/43184...

 

 

 

Sub Main()

'Grab the Assembly Document

Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument 'Grab the Active Assembly Component Definition

Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition ' Get the model browser

Dim oPane As BrowserPane oPane = oDoc.BrowserPanes.Item("Model") ' Grab the occurrence of the object Dim oOcc As ComponentOccurrence For Each oOcc In oDoc.ComponentDefinition.Occurrences 'Grab Document from Occurrence

Dim oOccDoc As Document oOccDoc = oOcc.Definition.Document 'get design properties set'

Dim invDesignInfo As PropertySet invDesignInfo = oOccDoc.PropertySets.Item("Design Tracking Properties") ' Get the part number property.

Dim invPartNumberProperty As Inventor.Property invPartNumberProperty = invDesignInfo.Item("Part Number") ' Get the browser node that corresponds to the new item

Dim oSubAssyNode As BrowserNode oSubAssyNode = oPane.GetBrowserNodeFromObject(oOcc) If oSubAssyNode.NativeObject.Name <> invPartNumberProperty.Value Then 'Set The name
oSubAssyNode.NativeObject.Name = (invPartNumberProperty.Value) End If Next End Sub

 

 

I know I’m not doing a good job explaining how to do this but I can see the whole thing in my head working… If I get some free time I might try to lay the whole thing out. Sorry wish I Could be more help.  

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report