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 ) Automatic Update Flat Pattern Extents

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
qsroos
2154 Views, 14 Replies

(iLogic ) Automatic Update Flat Pattern Extents

Hi I am looking for a ilogic rule to do the following . My ilogic skills are way to limited for me to be able achieve this, any help would be greatly appreciated

 

I need a rule to first look and see if the part is a sheet metal part, if yes then create flat pattern , create 2 parameters called Lenghtext. and Widthext. and add flatpattern extents values to these parameters . Also I need it to create custom Iproperties with these same names and values . Also if it could then update this documement with changes .

 

I am planning to run this as a external rule so it runs on any file that i have open ..

 

I am currently working on inventor 2014 .

 

Please any help in this regard would be greatly appreciated as this automation would save me hours trying to get all the appropriate details on a bo and in part lists ...

 

Regards

Quintin Roos

Tags (1)
14 REPLIES 14
Message 2 of 15
humbertogo
in reply to: qsroos

        ' Check that the document is a sheet metal document.
            If DocumentObject.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

           

   If not osheetMetalCompDef.HasFlatPattern Then

          osheetMetalCompDef.Unfold()

 use

ExposedAsProperty

<Sheet Metal Width>

<Sheet Metal Length>

Message 3 of 15
qsroos
in reply to: humbertogo

Thanks for the reply . However I am still unable to get this to work .

 

If someone could please help me with a complete rule or an explanation of how to complete that would be appreciated .

Message 4 of 15
humbertogo
in reply to: qsroos

 

' Set a reference to the sheet metal document.
        ' This assumes a part document is active.
        Dim oPartDoc As PartDocument
        oPartDoc = _InvApplication.ActiveDocument

        ' Make sure the document is a sheet metal document.
        If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
            MsgBox("A sheet metal document must be open.")
            Exit Sub
        End If

        ' Get the sheet metal component definition. Because this is a part document whose
        ' sub type is sheet metal, the document will return a SheetMetalComponentDefinition
        ' instead of a PartComponentDefinition.
        Dim oSheetMetalCompDef As SheetMetalComponentDefinition
        oSheetMetalCompDef = oPartDoc.ComponentDefinition

        If Not oSheetMetalCompDef.HasFlatPattern Then
            oSheetMetalCompDef.Unfold()
            oPartDoc.Update2(True)
        End If
        CustomiProperty(oPartDoc, m_widthName, "=<Sheet Metal Width>")
        CustomiProperty(oPartDoc, m_lengthName, "=<Sheet Metal Length>")
        CustomiProperty(oPartDoc, m_AreaFlat, "=<Sheet Metal Area>")


  Public Sub CustomiProperty(ByRef Doc As Inventor.Document, _
                                         ByRef PropertyName As String, _
                                         ByRef PropertyValue As Object)
        ' Get the custom property set. 
        Dim customPropSet As Inventor.PropertySet
        customPropSet = Doc.PropertySets.Item( _
        "Inventor User Defined Properties")


        If customPropSet IsNot Nothing Then
            ' Get the existing property, if it exists. 
            Dim prop As Inventor.Property = Nothing
            Dim propExists As Boolean = True
            Try
                prop = customPropSet.Item(PropertyName)
            Catch ex As Exception
                propExists = False
            End Try

            ' Check to see if the property was successfully obtained. 
            If Not propExists Then
                ' Failed to get the existing property so create a new one. 
                prop = customPropSet.Add(PropertyValue, PropertyName)
            Else
                ' Change the value of the existing property. 
                prop.Value = PropertyValue
            End If
        End If
    End Sub

 

Message 5 of 15
qsroos
in reply to: humbertogo

Thank you for your reply ..

 

This is the rule that i am using however there is still one small problem that i cant fiqure out . 

 

Imports  Inventor.UnitsTypeEnum
        
Dim oParams As Parameters
oParams=ThisDoc.Document.ComponentDefinition.Parameters
                
Dim oUserParams As UserParameters
oUserParams=oParams.UserParameters     
'look for user parameter and try to set it                
Try
oUserParams("lengthExtents").Value = SheetMetal.FlatExtentsLength /10
oUserParams("widthExtents").Value = SheetMetal.FlatExtentsWidth /10
Catch
' assume error means not found and create it
oUserParams.AddByValue("lengthExtents", SheetMetal.FlatExtentsLength /10, kmillimeterLengthUnits)
oUserParams.AddByValue("widthExtents", SheetMetal.FlatExtentsWidth /10, kmillimeterLengthUnits)
End Try
'ensure the parameters are exported/exposed as custom iProperties
Parameter.Param("lengthExtents").ExposedAsProperty = True
Parameter.Param("widthExtents").ExposedAsProperty = True
Parameter.Param("Thickness").ExposedAsProperty = True
'set the description to read in the iProperties
iProperties.Value("Project", "Stock Number") = "=<Thickness>PL x <widthExtents> x <lengthExtents>"

'update the file
iLogicVb.UpdateWhenDone = True

 I need it to also change the custom property format see image below

 

Untitled 123.png

 

 

 

I thank you for your assistance . Once this can be done it will work perfectly

Message 6 of 15
humbertogo
in reply to: qsroos

you can use

for example

UserParameter .CustomPropertyFormat.ShowLeadingZeros = True

Message 7 of 15
qsroos
in reply to: humbertogo

thanks final code is here :

 

Imports  Inventor.UnitsTypeEnum
        
Dim oParams As Parameters
oParams=ThisDoc.Document.ComponentDefinition.Parameters
                
Dim oUserParams As UserParameters
oUserParams=oParams.UserParameters     
'look for user parameter and try to set it                
Try
oUserParams("lengthExtents").Value = SheetMetal.FlatExtentsLength /10
oUserParams("widthExtents").Value = SheetMetal.FlatExtentsWidth /10
Catch
' assume error means not found and create it
oUserParams.AddByValue("lengthExtents", SheetMetal.FlatExtentsLength /10, kmillimeterLengthUnits)
oUserParams.AddByValue("widthExtents", SheetMetal.FlatExtentsWidth /10, kmillimeterLengthUnits)
End Try
'ensure the parameters are exported/exposed as custom iProperties
Parameter.Param("lengthExtents").ExposedAsProperty = True
Parameter.Param("widthExtents").ExposedAsProperty = True
Parameter.Param("Thickness").ExposedAsProperty = True
'set the description to read in the iProperties
iProperties.Value("Project", "Stock Number") = "=<Thickness>PL x <widthExtents> x <lengthExtents>"

Parameter.Param("lengthExtents").CustomPropertyFormat.ShowLeadingZeros = False
Parameter.Param("lengthExtents").CustomPropertyFormat.ShowTrailingZeros = False
Parameter.Param("lengthExtents").CustomPropertyFormat.ShowUnitsString = False

Parameter.Param("widthExtents").CustomPropertyFormat.ShowLeadingZeros = False
Parameter.Param("widthExtents").CustomPropertyFormat.ShowTrailingZeros = False
Parameter.Param("widthExtents").CustomPropertyFormat.ShowUnitsString = False

Parameter.Param("Thickness").CustomPropertyFormat.ShowLeadingZeros = False
Parameter.Param("Thickness").CustomPropertyFormat.ShowTrailingZeros = False
Parameter.Param("Thickness").CustomPropertyFormat.ShowUnitsString = False

'update the file
iLogicVb.UpdateWhenDone = True

 

Message 8 of 15
qsroos
in reply to: qsroos

It never ends . Could you please tell me how would i set the precision on that same rule for example to say 24 instead of 24.4369

Message 9 of 15
humbertogo
in reply to: qsroos

.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kFourDecimalPlacesPrecision

Message 10 of 15
qsroos
in reply to: humbertogo

Once again I thank you for your assistance I was not able to get the precision part to work . however I managed to do it a bit differently. i will post the final code here if any one else needs to use it . 

 

This allows me to show plate dimensions on bill of materials so costing and purchasing can be calculated from it . 

 

 

Imports  Inventor.UnitsTypeEnum
        
Dim oParams As Parameters
oParams=ThisDoc.Document.ComponentDefinition.Parameters
                
Dim oUserParams As UserParameters
oUserParams=oParams.UserParameters     
'look for user parameter and try to set it                
Try
oUserParams("lengthExtents").Value = Round(SheetMetal.FlatExtentsLength /10)
oUserParams("widthExtents").Value = Round(SheetMetal.FlatExtentsWidth /10)
Catch
' assume error means not found and create it
oUserParams.AddByValue("lengthExtents", Round(SheetMetal.FlatExtentsLength /10), kmillimeterLengthUnits)
oUserParams.AddByValue("widthExtents", Round(SheetMetal.FlatExtentsWidth /10), kmillimeterLengthUnits)
oUserParams.AddByValue("Thickness", Round(Thickness/10), kmillimeterLengthUnits)
End Try
'ensure the parameters are exported/exposed as custom iProperties
Parameter.Param("lengthExtents").ExposedAsProperty = True
Parameter.Param("widthExtents").ExposedAsProperty = True
Parameter.Param("Thickness").ExposedAsProperty = True
'set the description to read in the iProperties
iProperties.Value("Project", "Stock Number") = "=<Thickness>PL x <widthExtents> x <lengthExtents>"

Parameter.Param("lengthExtents").CustomPropertyFormat.ShowLeadingZeros = False
Parameter.Param("lengthExtents").CustomPropertyFormat.ShowTrailingZeros = False
Parameter.Param("lengthExtents").CustomPropertyFormat.ShowUnitsString = False

Parameter.Param("widthExtents").CustomPropertyFormat.ShowLeadingZeros = False
Parameter.Param("widthExtents").CustomPropertyFormat.ShowTrailingZeros = False
Parameter.Param("widthExtents").CustomPropertyFormat.ShowUnitsString = False

Parameter.Param("Thickness").CustomPropertyFormat.ShowLeadingZeros = False
Parameter.Param("Thickness").CustomPropertyFormat.ShowTrailingZeros = False
Parameter.Param("Thickness").CustomPropertyFormat.ShowUnitsString = False

'update the file
iLogicVb.UpdateWhenDone = True

 

Message 11 of 15
humbertogo
in reply to: qsroos

Hi qroos,

 

Code work fine and set the precision work fine.

It's CustomPropertyFormat look at the CustomProperty

For the Thickness you don't need to create a UserParameter once you ExposedAsProperty

is create automatic a CustomProperty Thickness

 

For the doc you can use the Unit of Measure

something like

 

 Dim oUOM As UnitsOfMeasure = InvDocument.UnitsOfMeasure

            ' Set the units and precision.
            oUOM.LengthDisplayPrecision = 4

 

Imports  Inventor.UnitsTypeEnum
        
Dim oParams As Parameters
oParams=ThisDoc.Document.ComponentDefinition.Parameters
                
Dim oUserParams As UserParameters
oUserParams=oParams.UserParameters     
'look for user parameter and try to set it                
Try
oUserParams("lengthExtents").Value = Round(SheetMetal.FlatExtentsLength /10)
oUserParams("widthExtents").Value = Round(SheetMetal.FlatExtentsWidth /10)
Catch
' assume error means not found and create it
oUserParams.AddByValue("lengthExtents", Round(SheetMetal.FlatExtentsLength /10), kmillimeterLengthUnits)
oUserParams.AddByValue("widthExtents", Round(SheetMetal.FlatExtentsWidth /10), kmillimeterLengthUnits)
'oUserParams.AddByValue("Thickness", Round(Thickness/10), kmillimeterLengthUnits)
End Try
'ensure the parameters are exported/exposed as custom iProperties
Parameter.Param("lengthExtents").ExposedAsProperty = True
Parameter.Param("widthExtents").ExposedAsProperty = True
Parameter.Param("Thickness").ExposedAsProperty = True

'set the description to read in the iProperties
iProperties.Value("Project", "Stock Number") = "=<Thickness>PL x <widthExtents> x <lengthExtents>"

Parameter.Param("lengthExtents").CustomPropertyFormat.ShowLeadingZeros = False
Parameter.Param("lengthExtents").CustomPropertyFormat.ShowTrailingZeros = False
Parameter.Param("lengthExtents").CustomPropertyFormat.ShowUnitsString = False

Parameter.Param("widthExtents").CustomPropertyFormat.ShowLeadingZeros = False
Parameter.Param("widthExtents").CustomPropertyFormat.ShowTrailingZeros = False
Parameter.Param("widthExtents").CustomPropertyFormat.ShowUnitsString = False

With Parameter.Param("Thickness")
               .CustomPropertyFormat.ShowLeadingZeros = False
               .CustomPropertyFormat.ShowTrailingZeros = False
               .CustomPropertyFormat.ShowUnitsString = False
               .CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kFourDecimalPlacesPrecision
End With
'update the file
iLogicVb.UpdateWhenDone = True

 

Message 12 of 15
qsroos
in reply to: humbertogo

Cool Thanks a million . 

Message 13 of 15

I had to revive this thread after a long time. For example, a sheet of 377mm x 663mm x 3mm is written as 380x660x3. How can I write with fractions? Can anyone help? I am using the code below.

ersin_karacoban_0-1684244540416.png

ersin_karacoban_1-1684244606108.png

 

Imports  Inventor.UnitsTypeEnum
        
Dim oParams As Parameters
oParams=ThisDoc.Document.ComponentDefinition.Parameters
                
Dim oUserParams As UserParameters
oUserParams=oParams.UserParameters     
'look for user parameter and try to set it                
Try
oUserParams("lengthExtents").Value = Round(SheetMetal.FlatExtentsLength/10)
oUserParams("widthExtents").Value = Round(SheetMetal.FlatExtentsWidth/10)
Catch
' assume error means not found and create it
oUserParams.AddByValue("lengthExtents", Round(SheetMetal.FlatExtentsLength /10), kMillimeterLengthUnits)
oUserParams.AddByValue("widthExtents", Round(SheetMetal.FlatExtentsWidth /10), kMillimeterLengthUnits)
'oUserParams.AddByValue("Thickness", Round(Thickness/10), kmillimeterLengthUnits)
End Try
'ensure the parameters are exported/exposed as custom iProperties
Parameter.Param("lengthExtents").ExposedAsProperty = True
Parameter.Param("widthExtents").ExposedAsProperty = True
Parameter.Param("Thickness").ExposedAsProperty = True

'set the description to read in the iProperties
iProperties.Value("Project", "Description") = "=<Thickness> x <widthExtents> x <lengthExtents>"

Parameter.Param("lengthExtents").CustomPropertyFormat.ShowLeadingZeros = True
Parameter.Param("lengthExtents").CustomPropertyFormat.ShowTrailingZeros = False
Parameter.Param("lengthExtents").CustomPropertyFormat.ShowUnitsString = True

Parameter.Param("widthExtents").CustomPropertyFormat.ShowLeadingZeros = True
Parameter.Param("widthExtents").CustomPropertyFormat.ShowTrailingZeros = False
Parameter.Param("widthExtents").CustomPropertyFormat.ShowUnitsString = True

With Parameter.Param("Thickness")
               .CustomPropertyFormat.ShowLeadingZeros = True
               .CustomPropertyFormat.ShowTrailingZeros = False
               .CustomPropertyFormat.ShowUnitsString = True
               .CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kfourDecimalPlacesPrecision	
	End With
'update the file
iLogicVb.UpdateWhenDone = True

 

 

Message 14 of 15

Hi @ersin_karacoban.  When you are dealing with metric values, such as centimeters or millimeters, the option to present the value as a fraction is eliminated.  If you were using inches or feet type units, you would be able to specify fractions as an option for the value's formatting.  And if the units were inches or feet, then you could choose one of the options within the CustomPropertyPrecisionEnum that mentions fractions, to format the value that way.  As for the inaccurate numerical results, I see that you are using the Round() method within your code to round off the numerical value.  You may have to be more specific with that method to get more accurate results.  There are several possible variations, or ways to use that method, as you can see at the linked Microsoft web page.

https://learn.microsoft.com/en-us/dotnet/api/system.math.round 

Wesley Crihfield

EESignature

Message 15 of 15
Frederick_Law
in reply to: qsroos

Metric in fraction ?!???!

3 1/32 mm?

3 3125/100000 mm?

Really?

ISO allow that?

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

Post to forums  

Autodesk Design & Make Report