Creating a sketch and Converting Parameters using iLogic

Creating a sketch and Converting Parameters using iLogic

Anonymous
Not applicable
1,540 Views
18 Replies
Message 1 of 19

Creating a sketch and Converting Parameters using iLogic

Anonymous
Not applicable

Hi all, 

I'm having trouble creating and converting parameters and would love some help, of course, I'm new to iLogic and I'm sure what I'd like to do is simple for most. 

What we currently do:

I create two sketches in a finished assembly and then use those Parameters as LENGTH, WIDTH, THICK all in mm then I Create user parameters manually as ELENGTH, EWIDTH, ETHICK and use the LENGTH, WIDTH, THICK Parameters and set the units to in, Fractional, 1/16 precision.

 

Priority/Question 1: 

I'd like to automate this with iLogic and have the rule either create the sketch and all the parameters for me including setting the "Custom Property Format"  or skip the sketch but still grab the required dims to create the parameters needed, this would help so much to speed up the process for everyone in my dept.

 

"else if" Priority/Question 2:

If creating the sketch or grabbing the dims is to complicated I would atleast like to know how to convert the LENGTH, WIDTH, THICK Parameters to ELENGTH, EWIDTH, ETHICK and set the "Custom Property Formats" for both mm and inches.

 

See the attached image if it helps.

Thank you!  Any help with this would be greatly appreciated.iLogic Needed to Convert mm to inches creating in a new user parameter.PNG

 

 

0 Likes
1,541 Views
18 Replies
Replies (18)
Message 2 of 19

Sergio.D.Suárez
Mentor
Mentor

If you have the assembly aligned with the main planes
have you tried the "RangeBox" property?
for this property you can access two points, a maximum and a minimum, and you can set the dimensions from here, so you would not have to create a sketch and reference this to the edges of each point in the periphery of the assembly.
If I did not understand badly I see that you need the virtual dimensions that your assembly would occupy. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 19

bradeneuropeArthur
Mentor
Mentor

Hi,

@Sergio.D.Suárez 

 

But as you already comment, this (Rangebox) only works when the assembly is orientated correctly to XYZ!

otherwise if you like, we can share the code for the rangebox dimensions..

 

Regards, 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 19

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Hoping that below iLogic code may be helpful to converting parameters.

Sub Main()
    Dim oDoc As PartDocument
    oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As PartComponentDefinition
    oDef = oDoc.ComponentDefinition
    
    Dim oParam As UserParameter
    For Each oParam In oDef.Parameters.UserParameters
        If oParam.Name = "ELENGTH" Or oParam.Name = "EWIDTH" Or oParam.Name = "ETHICK" Then
            oParam.Units = "in"
        End If
    Next
    
    
End Sub

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 19

Anonymous
Not applicable

Thank you Sergio, I've actually never heard of that, it's a new one to me but looks promising.  

Do you have an example of what the rule would look like?

 

0 Likes
Message 6 of 19

bradeneuropeArthur
Mentor
Mentor

I have.

You need it?

 

Dim a As PartDocument ' or Document ' or AssemblyDocument
Set a = ThisApplication.ActiveDocument

Dim b As ComponentDefinition
Set b = a.ComponentDefinition

Dim c As Box
Set c = b.RangeBox

'Dim c1 As SurfaceBody
'Set c1 = b.SurfaceBodies.Item.Item(1)

'Dim c2 As Box
'Set c2 = c1.RangeBox

'Dim c3 As Variant
'Set c3 = c2.MaxPoint
'b.Occurrences.Item (1).RangeBox.

Dim dmax As Point
Set dmax = c.MaxPoint

Dim dmin As Point
Set dmin = c.MinPoint


MsgBox dmax.X - dmin.X & " " & dmax.Y - dmin.Y & " " & dmax.Z - dmin.Z

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 7 of 19

Anonymous
Not applicable

Braden, that would be GREAT.  

 

Most assemblies are centered on origin in the xy and the z is normally used as the ground or floor plane at least in our larger Assemblies.  So the center origin, in all of our assemblies normally isn't exactly center, a lot of times two planes are and one isn't and some co-workers assemblies or old assemblies just aren't centered at all.

So any rule that would work without depending the center origin would be amazing!

0 Likes
Message 8 of 19

Anonymous
Not applicable

Braden,

Thank you!  

Is there anything else I need to do to make this work?  

I copied/pasted, it wanted parenthesize on the msgbox, I added them and got this.  Which is great!  

Now how do I get that into my parameters as mm (THICK, LENGTH, WIDTH) and then create another in inches (ETHICK, ELENGTH, EWIDTH) ?  

Get Dims Snippet.PNG

0 Likes
Message 9 of 19

bradeneuropeArthur
Mentor
Mentor

keep reading..

 

Dim a As PartDocument ' or Document ' or AssemblyDocument
a = ThisApplication.ActiveDocument

Dim b As ComponentDefinition
b = a.ComponentDefinition

Dim c As Box
c = b.RangeBox


Dim dmax As Point
dmax = c.MaxPoint

Dim dmin As Point
dmin = c.MinPoint


MsgBox(dmax.X - dmin.X & " cm " & dmax.Y - dmin.Y & " cm " & dmax.Z - dmin.Z & " cm ")
Try
	Parameter("Le") = dmax.X - dmin.X

	Catch
Dim pa1 As Inventor.Parameter
pa1 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("Le", dmax.X - dmin.X, "inch")		
		End Try

Try
	Parameter("Wi") = dmax.Y - dmin.Y
	Catch
Dim pa2 As Inventor.Parameter
pa2 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("Wi", dmax.Y - dmin.Y, "inch")
 		End Try
 
 Try
	 Parameter("Thi") = dmax.Z - dmin.Z
	 Catch
		 
Dim pa3 As Inventor.Parameter
pa3 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("Thi",dmax.Z - dmin.Z,"inch")
		End Try
'Dim p As Inventor.Property = Nothing
'Try
'	'p = a.PropertySets.Item(4).Add(dmax.X - dmin.X, "dimX")
'	Catch 
'		'iProperties.Value("Custom", "dimX")= dmax.X - dmin.X
'		End Try

''p = a.PropertySets.Item(4).Add("100", "dimY")
'p = a.PropertySets.Item(4).Add(dmax.Z - dmin.Z,"dimY")

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 10 of 19

Sergio.D.Suárez
Mentor
Mentor

If the assembly is parallel to the main planes, the offset does not matter with respect to the origin, the rule will give you the value you need. Please check it regards

 

Dim oDoc As Document = ThisDoc.Document
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
Dim oBox As Box = oCD.RangeBox

Dim oX As Double = Round(oCD.RangeBox.MaxPoint.X - oCD.RangeBox.MinPoint.X,2)*10
Dim oY As Double = Round(oCD.RangeBox.MaxPoint.Y - oCD.RangeBox.MinPoint.Y,2)*10
Dim oZ As Double = Round(oCD.RangeBox.MaxPoint.Z - oCD.RangeBox.MinPoint.Z,2)*10

oLong = MaxOfMany(oX,oY,oZ)
oWid = MinOfMany(oX, oY, oZ)
oHigh = oX + oY + oZ - oLong - oWid

MsgBox("Length: " & oLong & " mm" & vbCrLf & _
		"Width: " & oWid & " mm" & vbCrLf & _
		"High: " & oHigh & " mm" )

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 11 of 19

Anonymous
Not applicable
Wow, they both work great!  Thank you both very much!
Braden that worked and added it to the parameters perfectly and I was able to copy and paste and
add the "LENGTH" for mm which worked as well but how do I now add the following and make it an
exported parameter and set the precision and everything like below?

'Parameter.Param("ELENGTH").ExposedAsProperty = True
'Parameter.Param("ELENGTH").CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision 'Parameter.Param("ELENGTH").CustomPropertyFormat.ShowTrailingZeros = False 'Parameter.Param("ELENGTH").CustomPropertyFormat.ShowLeadingZeros = False 'Parameter.Param("ELENGTH").CustomPropertyFormat.ShowUnitsString = False ''Parameter.Param("ELENGTH").CustomPropertyFormat.Units = "in"

and also
'Parameter.Param("LENGTH").ExposedAsProperty = True 
'Parameter.Param("LENGTH").CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision 
'Parameter.Param("LENGTH").CustomPropertyFormat.ShowTrailingZeros = False
'Parameter.Param("LENGTH").CustomPropertyFormat.ShowLeadingZeros = False 
'Parameter.Param("LENGTH").CustomPropertyFormat.ShowUnitsString = False 
'Parameter.Param("LENGTH").CustomPropertyFormat.Units = "mm" 
 
0 Likes
Message 12 of 19

Anonymous
Not applicable

Does anyone know how to incorporate the above into either rule?  I'm sure it's easy and I'm just to knew to this to know but it's the last piece to my puzzle and this rule will help us a ton.

 

Thanks again for the help!

0 Likes
Message 13 of 19

bradeneuropeArthur
Mentor
Mentor
Dim a As PartDocument ' or Document ' or AssemblyDocument
a = ThisApplication.ActiveDocument

Dim b As ComponentDefinition
b = a.ComponentDefinition

Dim c As Box
c = b.RangeBox


Dim dmax As Point
dmax = c.MaxPoint

Dim dmin As Point
dmin = c.MinPoint


MsgBox(dmax.X - dmin.X & " cm " & dmax.Y - dmin.Y & " cm " & dmax.Z - dmin.Z & " cm ")
Try
	Parameter("Length") = dmax.X - dmin.X

	Catch
Dim pa1 As Inventor.Parameter
pa1 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("Length", dmax.X - dmin.X, "mm")	
pa1.ExposedAsProperty = True
pa1.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
pa1.CustomPropertyFormat.ShowTrailingZeros = False
pa1.CustomPropertyFormat.ShowLeadingZeros = False
pa1.CustomPropertyFormat.ShowUnitsString = False
pa1.CustomPropertyFormat.Units = "mm"
		End Try

Try
	Parameter("Width") = dmax.Y - dmin.Y
	Catch
Dim pa2 As Inventor.Parameter
pa2 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("Width", dmax.Y - dmin.Y, "mm")
pa2.ExposedAsProperty = True
pa2.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
pa2.CustomPropertyFormat.ShowTrailingZeros = False
pa2.CustomPropertyFormat.ShowLeadingZeros = False
pa2.CustomPropertyFormat.ShowUnitsString = False
pa2.CustomPropertyFormat.Units = "mm"
 		End Try
 
 Try
	 Parameter("Thickness") = dmax.Z - dmin.Z
	 Catch
		 
Dim pa3 As Inventor.Parameter
pa3 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("Thickness", dmax.Z - dmin.Z, "mm")
pa3.ExposedAsProperty = True
pa3.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
pa3.CustomPropertyFormat.ShowTrailingZeros = False
pa3.CustomPropertyFormat.ShowLeadingZeros = False
pa3.CustomPropertyFormat.ShowUnitsString = False
pa3.CustomPropertyFormat.Units = "mm"
		End Try

Try
	Parameter("ELength") = dmax.X - dmin.X

	Catch
Dim Epa1 As Inventor.Parameter
Epa1 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("ELength", dmax.X - dmin.X, "inch")	
Epa1.ExposedAsProperty = True
Epa1.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
Epa1.CustomPropertyFormat.ShowTrailingZeros = False
Epa1.CustomPropertyFormat.ShowLeadingZeros = False
Epa1.CustomPropertyFormat.ShowUnitsString = False
Epa1.CustomPropertyFormat.Units = "inch"
		End Try

Try
	Parameter("EWidth") = dmax.Y - dmin.Y
	Catch
Dim Epa2 As Inventor.Parameter
Epa2 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("EWidth", dmax.Y - dmin.Y, "inch")
Epa2.ExposedAsProperty = True
Epa2.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
Epa2.CustomPropertyFormat.ShowTrailingZeros = False
Epa2.CustomPropertyFormat.ShowLeadingZeros = False
Epa2.CustomPropertyFormat.ShowUnitsString = False
Epa2.CustomPropertyFormat.Units = "inch"
 		End Try
 
 Try
	 Parameter("EThickness") = dmax.Z - dmin.Z
	 Catch
		 
Dim Epa3 As Inventor.Parameter
Epa3 = a.ComponentDefinition.Parameters.UserParameters.AddByValue("EThickness", dmax.Z - dmin.Z, "inch")
Epa3.ExposedAsProperty = True
Epa3.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
Epa3.CustomPropertyFormat.ShowTrailingZeros = False
Epa3.CustomPropertyFormat.ShowLeadingZeros = False
Epa3.CustomPropertyFormat.ShowUnitsString = False
Epa3.CustomPropertyFormat.Units = "inch"
		End Try

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 14 of 19

Anonymous
Not applicable

Oh thank you so much!!!  I appreciate you taking the time to do that. 

 

It works great but it only wants to add one line of ELENGTH, EWIDTH, OR ETHICK at a time and then I get (Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)).  So it runs, throws an error, when I look in parameters the first time it added Length, width, thick, and ELength.  Then when I try it again it adds EWidth and throws the error again, and then the third time ran it adds EThick and does not throw the error.  It's odd, not sure what it's missing to complete it and add them all the first time...?ELENGTH Snippet.PNG

0 Likes
Message 15 of 19

Anonymous
Not applicable

I hate to ask about this after you've already helped so much but do you get or know why that rule is doing what I mentioned above?

0 Likes
Message 16 of 19

JamieVJohnson2
Collaborator
Collaborator

It is in the code structure, you are attempting to use the parameter before checking to see if it exists.  Then when the error is thrown, you add the parameter.  Not the cleanest way, because error capturing actually slows down your code.  You can do a find parameter, then add if not found.  THEN move on to set the parameter value.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 17 of 19

Anonymous
Not applicable

Thank you Jamie,

whats the line your thinking/referencing that I should be using to search for or Find the parameter?  Just curious...  I'm so new to this it's still too much of a guessing game for me I'm short on time at the moment, any help would be and is very much appreciated.  Thanks again!  

0 Likes
Message 18 of 19

JamieVJohnson2
Collaborator
Collaborator

I think like this:

    Public Function FindParameter(invdoc As Inventor.Document, strParameter As String) As Parameter
        Dim cd As ComponentDefinition = Nothing
        Select Case invdoc.DocumentType
            Case Is = Inventor.DocumentTypeEnum.kAssemblyDocumentObject
                Dim docAssembly As Inventor.AssemblyDocument = invdoc
                cd = docAssembly.ComponentDefinition
            Case Is = Inventor.DocumentTypeEnum.kPartDocumentObject
                Dim docPart As Inventor.PartDocument = invdoc
                cd = docPart.ComponentDefinition
        End Select
        If cd IsNot Nothing Then
            For Each param As Parameter In cd.Parameters
                If param.Name = strParameter Then
                    Return param
                End If
            Next
        End If
        Return Nothing
    End Function

when looking for a parameter.

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 19 of 19

Anonymous
Not applicable

Another way to get the bounding box limit is to use the ExtentsLength, ExtentsWidth and ExtentsHeight from the code snippets under Measure. So it would be something like this.

Dim LengthLimit As Decimal = Measure.ExtentsLength 'gets the length (x direction) of the extents of the part/assembly
Dim WidthLimit As Decimal = Measure.ExtentsWidth 'gets the length (y direction) of the extents of the part/assembly
Dim HeightLimit As Decimal = Measure.ExtentsHeight 'gets the length (z direction) of the extents of the part/assembly

Just another way. Hope that helps.

 

DanV