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
Solved! Go to Solution.
Solved by qsroos. Go to Solution.
Solved by qsroos. Go to Solution.
Solved by humbertogo. Go to Solution.
' 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>
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 .
' 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
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
I thank you for your assistance . Once this can be done it will work perfectly
you can use
for example
UserParameter .CustomPropertyFormat.ShowLeadingZeros = True
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
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
.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kFourDecimalPlacesPrecision
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
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
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.
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
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
Metric in fraction ?!???!
3 1/32 mm?
3 3125/100000 mm?
Really?
ISO allow that?