Inventor Customization

Inventor Customization

Reply
New Member
silenzo
Posts: 1
Registered: ‎01-07-2013
Message 1 of 2 (429 Views)

iLogic - running script for each part in assembly

429 Views, 1 Replies
01-08-2013 02:33 PM

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?

ADN Support Specialist
Vladimir.Ananyev
Posts: 475
Registered: ‎08-14-2012
Message 2 of 2 (385 Views)

Re: iLogic - running script for each part in assembly

01-14-2013 01:36 AM 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

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.