Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic - running script for each part in assembly

1 REPLY 1
Reply
Message 1 of 2
silenzo
1132 Views, 1 Reply

iLogic - running script for each part in assembly

Hello,

 

I'm trying to write a script which would process all the ipt files within assembly and launch certain functions according to a ipt file type.

I've already made such script for dimensioning parts which work for standart parts but not for metal sheets.

Here it is:

 

Sub Main
  Dim oApp As Inventor.Application =  ThisApplication
  Dim oAssy As Inventor.AssemblyDocument = oApp.ActiveDocument

  For Each oSubDoc as Inventor.Document In oAssy.AllReferencedDocuments
    If oSubDoc.DocumentType = kPartDocumentObject Then
       Dim oPartPropset As Inventor.PropertySet = oSubDoc.PropertySets("Design Tracking Properties")
       Dim oPartParam As Inventor.PropertySet = oSubDoc.PropertySets("Inventor User Defined Properties")

        Dim oParameter As Parameter
        For Each oParameter In oSubDoc.ComponentDefinition.Parameters
        oParameter.ExposedAsProperty = True
        Next oParameter

       If oSubDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
            Dim d1 = Round(SheetMetal.FlatExtentsLength, 1)
            Dim s1 = Round(SheetMetal.FlatExtentsWidth, 1)
            Dim g1 = Round(Parameter("Grubość"),1) 

            FindOrCreateProperty("Długość [mm]", d1, oSubDoc, True)
            FindOrCreateProperty("Szerokość [mm]", s1, oSubDoc, True)
            FindOrCreateProperty("Grubość [mm]", g1, oSubDoc, True)

      Else If oSubDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

            Dim Xmax=oSubDoc.ComponentDefinition.RangeBox.MaxPoint.X
            Dim Ymax=oSubDoc.ComponentDefinition.RangeBox.MaxPoint.Y
            Dim Zmax=oSubDoc.ComponentDefinition.RangeBox.MaxPoint.Z
            Dim Xmin=oSubDoc.ComponentDefinition.RangeBox.MinPoint.X
            Dim Ymin=oSubDoc.ComponentDefinition.RangeBox.MinPoint.Y
            Dim Zmin=oSubDoc.ComponentDefinition.RangeBox.MinPoint.Z

            Dim f1= ((Xmax-Xmin)*10)
            Dim f2= ((Ymax-Ymin)*10)
            Dim f3= ((Zmax-Zmin)*10)

            Dim h1=MinOfMany(f1, f2, f3)
            Dim h2=MaxOfMany(f1, f2, f3)
            Dim h3=(f1+f2+f3)-h1-h2

            FindOrCreateProperty("Długość [mm]", (FormatNumber(h2,1)), oSubDoc, True)
            FindOrCreateProperty("Szerokość [mm]", (FormatNumber(h3,1)), oSubDoc, True)
            FindOrCreateProperty("Grubość [mm]", (FormatNumber(h1,1)), oSubDoc, True)


    End If
    End If

  Next

  oAssy = Nothing
  oApp = Nothing


End Sub 

 

 

this code distinguishes parts from sheet metal, and launches appropriate functions to get their dimmensions. It just doesnt work for metal sheets somehow. Seems like SheetMetal.FlatExtentsLength is performed from within the assembly, not part as it should be. I must have the addressing wrong. I've tried many things and different functions but nothing works for sheet metal parts. Maybe someone have an idea how to solve this?

 

and one more thing. This code might also be useful for different purposes. I'm also trying to lunch some external scripts for each part within an assembly, but there is no direct function for that (there is one only for internal scripts , based within the file). Any ideas?

1 REPLY 1
Message 2 of 2
Vladimir.Ananyev
in reply to: silenzo

Function SheetMetal.FlatExtentsLength works in the context of active sheet document. But your active document is an assembly.  So this method fails.   Please try this approach:

 

If oSubDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
    'have sheet metal part
    Dim oDef As SheetMetalComponentDefinition _
          = oSubDoc.ComponentDefinition
    Dim oFlatPattern As FlatPattern = oDef.FlatPattern
    
    'get flat pattern properties
    Dim d1 as Double = Round(oFlatPattern.Length, 1)
    Dim s1 as Double = Round(oFlatPattern.Width, 1)
    
    Beep  'debug output
    MsgBox(d1 & vbNewLine & s1 )
    
Else  
    ' here is code for normal parts
    ' .................	
    
End If

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

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

Post to forums  

Autodesk Design & Make Report