Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ilogic Round

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
oryon.fuYUBXD
414 Views, 4 Replies

Ilogic Round

Hi,

 

Any ideas on how to round the THICKNESS, LENGTH, WITDH to 1 decimal place?

All these values are generated in ilogic based on the max length, width, and thickness with the code as follow:

 

L1 = Measure.ExtentsLength
L2 = Measure.ExtentsWidth
L3 = Measure.ExtentsHeight
 
 
'Sort measurements
 
THK = MinOfMany(L1,L2,L3)
LTH = MaxOfMany(L1,L2,L3)
WTH = L1 + L2 + L3 - THK - LTH
 
 
'Create external custom parameters
 
iProperties.Value("custom","LENGTH") = LTH
iProperties.Value("custom","WIDTH") = WTH
iProperties.Value("custom","THICKNESS") = THK

 

oryonfuYUBXD_0-1662081468188.png

 

 

 

4 REPLIES 4
Message 2 of 5
pcrawley
in reply to: oryon.fuYUBXD

THK = Round(MinOfMany(L1,L2,L3) ,1)
LTH = Round(MaxOfMany(L1,L2,L3) ,1)
WTH = Round(L1 + L2 + L3 - THK - LTH ,1)
Peter
Message 3 of 5
pcrawley
in reply to: oryon.fuYUBXD

Sorry - I can't leave this without a word of caution about "Measure.Extents" (because I have been burnt by it!):  It assumes the bounding box is created about the origin planes.

 

This is OK for models created about the origin planes, but not when the model is created away from those planes.  This typically happens if you use derived parts created from multibody/skeletal modelling or some imported geometry. If the part you are measuring is at an angle from one (or more planes), the Measure.Extents results can be very confusing:

measure.jpg

In the case shown, the red shape is 5x5x10 - but Measure.Extents reports 11x10x10.  Measure.extents is reading the dimensions of the transparent box based on the origin planes.

 

For your case this might not be important, but if it is, I wouldn't want you to suffer as I did!  There is an alternative method using "OrientedMinimumRangeBox" - but the iLogic is more complicated.

Peter
Message 4 of 5

Hi Pcrawley,

 

You're absolutely right. I faced the same problem exactly!

Do you mind sharing your Ilogic by using "OrientedMinimumRangeBox" with me?

It will be really helpful.

 

Thanks

Message 5 of 5
pcrawley
in reply to: oryon.fuYUBXD

Sorry for the delay - I can't find the name of the person who put me onto this - I really wanted to give them the credit.  (I might post back later!)

 

Dim oDoc = ThisApplication.ActiveDocument
Dim oName = ThisDoc.Document.DisplayName

Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oSolid As SurfaceBody
Dim oUserParam As UserParameter
Dim oLength As Double

If oDef.SurfaceBodies.Count > 0 Then
	
	oSolid = oDef.SurfaceBodies.Item(1)
	dist1 = oSolid.OrientedMinimumRangeBox.DirectionOne.Length
	dist2 = oSolid.OrientedMinimumRangeBox.DirectionTwo.Length
	dist3 = oSolid.OrientedMinimumRangeBox.DirectionThree.Length
	
	LTH2 = (MaxOfMany(dist1, dist2, dist3))
	WTH2 = (MinOfMany(dist1, dist2, dist3))
	THK2 = (dist1 + dist2 + dist3 - LTH2 - WTH2)
	
	'Inventor's internal units of measure are centimeters, so need to apply conversion factor
	'For Metric n * 10
	'For Inches n * (1 / 2.54) = n * 0.394
unitConversion = 10 LTH2 = LTH2 * unitConversion WTH2 = WTH2 * unitConversion THK2 = THK2 * unitConversion iProperties.Value("custom","LENGTH2") = LTH2 iProperties.Value("custom","WIDTH2") = WTH2 iProperties.Value("custom", "THICKNESS2") = THK2 End If

The last lines are just for taking care of converting the internal units of Inventor (cm) into your preferred units.

 

You may also want to apply the rounding - as per your original post 😉

Peter

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

Post to forums  

Autodesk Design & Make Report