Apply Parameters and iProperties to subcomponents using iLogic based on thickness

Apply Parameters and iProperties to subcomponents using iLogic based on thickness

David.Berken
Participant Participant
450 Views
2 Replies
Message 1 of 3

Apply Parameters and iProperties to subcomponents using iLogic based on thickness

David.Berken
Participant
Participant

So I am trying to create some code that will allow me to assign custom iProperties and Parameters to components that have been exported from a Solid Body Model and put into an Assembly. The code I have found elsewhere on here and modified slightly measures the RangeBox in the X, Y, and Z directions and then assigns them to the appropriate Parameters. Then I have a long list of 'If' statements that assigns a custom iProperty if the thickness matches. This works for 90% of my parts but one specifically that will not work is the thickness of 0.8348. The code successfully applies the thickness to the parameter but when trying to assign the custom iProperty it does not recognize that as the thickness. I have pasted some code below to show how it works. Any suggestions for improvement or help on why only specific materials aren't working i would greatly appreciate it. 

 

Beginning Code To Set Parameters:

 

oAdoc = ThisApplication.ActiveDocument
oAcompdef = oAdoc.ComponentDefinition

'conversion factor cm to in
oCF = 2.54

 For Each oOcc In oAcompdef.Occurrences
	 
    Dim custParamSet As Parameters
    custParamSet=oOcc.Definition.Document.ComponentDefinition.Parameters
    ' Set access to Custom and Default iProperties
    Dim customPropSet As PropertySet   
 
 	oX = Math.Abs(oOcc.definition.RangeBox.MaxPoint.X _
		- oOcc.definition.RangeBox.MinPoint.X)/oCF
	oY = Math.Abs(oOcc.definition.RangeBox.MaxPoint.Y _
		- oOcc.definition.RangeBox.MinPoint.Y)/oCF
	oZ = Math.Abs(oOcc.definition.RangeBox.MaxPoint.Z _
		-oOcc.definition.RangeBox.MinPoint.Z)/oCF
	
	
	'get middle number
	If oX > oY And oX < oZ Or oX > oZ And oX < oY Then 	
		oMiddle = oX
		GoTo Set_Width
	End If 
	
	If oY > oX And oY < oZ Or oY > oZ And oY < oX Then 
		oMiddle = oY
		GoTo Set_Width
	End If 
	
	If oZ > oX And oZ < oY Or oZ > oY And oZ < oX Then 
		oMiddle = oZ
		GoTo Set_Width
	End If

	Set_Width :
	Parameter(oOcc.Name,"WD") = Round(oMiddle,4)

	'set length
	Parameter(oOcc.Name,"LG") = Round(MaxOfMany(oX, oY, oZ),4)

	'set Thickness
	Parameter(oOcc.Name, "THK") = Round(MinOfMany(oX, oY, oZ), 4)
	
	MsgBox(String.Format("{0:N6} x {1:N6} x {2:N6} [in]", Parameter(oOcc.Name,"LG"), Parameter(oOcc.Name,"WD"), Parameter(oOcc.Name, "THK")))

 

If Then Statement that works

 

	If Parameter(oOcc.Name, "THK") = 0.2363 Then
	iProperties.Value(oOcc.Name, "Custom", "RM_Properties") = "CELTEC 6 MM WHITE"
	End If

 

If Then Statement that does not work

 

	If Parameter(oOcc.Name, "THK") = 0.8348 Then
	iProperties.Value(oOcc.Name, "Custom", "RM_Properties") = "PARTICLE BOARD 3/4 L/L"
	End If

 

 

 

 

 

 

 

0 Likes
Accepted solutions (1)
451 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Is it possible that there may be a difference in the number of decimal places included in the accuracy of the comparison?  Maybe try seeing if the value is greater than (>) .833 And less than (<) .835 or something similar, just to see if it is an accuracy or tolerance related issue?

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

David.Berken
Participant
Participant

Thank you for your suggestion. This exact fix wasnt able to work for me since we have a lot of materials that would have a range within .001". Its a long story but basically your idea of the tolerances led me down the path to create a parameter in the code and then set my THK parameter on the part with that value and the assign the iProperty referencing that code parameter as well and it now seems to be working.

 

New Code with Parameters

oAdoc = ThisApplication.ActiveDocument
oAcompdef = oAdoc.ComponentDefinition

'conversion factor cm to in
oCF = 2.54

 For Each oOcc In oAcompdef.Occurrences
	 
    Dim custParamSet As Parameters
    custParamSet=oOcc.Definition.Document.ComponentDefinition.Parameters
    ' Set access to Custom and Default iProperties
    Dim customPropSet As PropertySet   
 
 	oX = Math.Abs(oOcc.definition.RangeBox.MaxPoint.X _
		- oOcc.definition.RangeBox.MinPoint.X)/oCF
	oY = Math.Abs(oOcc.definition.RangeBox.MaxPoint.Y _
		- oOcc.definition.RangeBox.MinPoint.Y)/oCF
	oZ = Math.Abs(oOcc.definition.RangeBox.MaxPoint.Z _
		-oOcc.definition.RangeBox.MinPoint.Z)/oCF
	
	
	'get middle number
	If oX > oY And oX < oZ Or oX > oZ And oX < oY Then 	
		oMiddle = oX
		GoTo Set_Width
	End If 
	
	If oY > oX And oY < oZ Or oY > oZ And oY < oX Then 
		oMiddle = oY
		GoTo Set_Width
	End If 
	
	If oZ > oX And oZ < oY Or oZ > oY And oZ < oX Then 
		oMiddle = oZ
		GoTo Set_Width
	End If

	Dim Width As Decimal
	Dim Length As Decimal
	Dim Thickness As Decimal
	
	'set Width
	Set_Width :
	Width = oMiddle
	Parameter(oOcc.Name,"WD") = Width

	'set length
	Length = MaxOfMany(oX, oY, oZ)
	Parameter(oOcc.Name,"LG") = Length

	'set Thickness
	Thickness = MinOfMany(oX, oY, oZ)
	Parameter(oOcc.Name,"THK") = Thickness
	
	MsgBox(String.Format("{0:N6} x {1:N6} x {2:N6} [in]", Length, Width, Thickness))

 

New If statements

	If Thickness = 0.2363 Then
	iProperties.Value(oOcc.Name, "Custom", "RM_Properties") = "CELTEC 6 MM WHITE"
	End If
	If Thickness = 0.8348 Then
	iProperties.Value(oOcc.Name, "Custom", "RM_Properties") = "PARTICLE BOARD 3/4 L/L"
	End If

 

Thank you so much for your help!

0 Likes