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 Formual

28 REPLIES 28
Reply
Message 1 of 29
andrew.warren
2065 Views, 28 Replies

iLogic Formual

I am trying to create a iLogic Rule that will measure the Length, Width and Thickness of a part and ut it into the custom fields we have. I am having a hard time rememebring how to get it to do it from the assembly level. I want to run this on the assembly and have it populate all the parts inside of it. The code below will do it for a part but what is it I add to get it to drill down into the assembly?

 

iProperties.Value("Custom", "THICKNESS")=Measure.ExtentsHeight

iProperties.Value("Custom", "WIDTH")=Measure.ExtentsWidth

iProperties.Value("Custom", "LENGTH")=Measure.ExtentsLength

 

Then I want ti to add this formyual to the Stock Number iProperty = <Length> X <Width>   I can get it to add the values but I can not get it to add the formual to the stock number.

 

I have 10,000 things to do and I can not concentrate long enough to figure this one out. Any help would be apprciated!

Andy Warren
BCDesign@bellsouth.net
28 REPLIES 28
Message 2 of 29

I am trying to get it to drill down into the part and fill out this info...

 

Format:HTML Format
Version:1.0
StartHTML: 165
EndHTML: 4413
StartFragment: 314
EndFragment: 4381
StartSelection: 314
EndSelection: 314

compo=Component.InventorComponent("PartA:1")

Try
iProperties.Value(compo, "Custom", "THICKNESS")=compoMeasure.ExtentsHeight

iProperties.Value(compo, "Custom", "WIDTH")=compoMeasure.ExtentsWidth

iProperties.Value(compo, "Custom", "LENGTH")=compoMeasure.ExtentsLength

Catch
EndTry

 

Andy Warren
BCDesign@bellsouth.net
Message 3 of 29
MegaJerk
in reply to: andrew.warren

Something like : 

'Assuming that you have three custom Properties named "MegaThickness" , "MegaLength", and "MegaWidth" I believe this will do what you'd like
'
'Be sure to fill out the correct custom properties that you actually are using ;) 



iProperties.Value("PartA:1", "Custom", "MegaThickness") = Measure.ExtentsHeight
iProperties.Value("PartA:1", "Custom", "MegaLength") = Round(Measure.ExtentsLength,2)
iProperties.Value("PartA:1", "Custom", "MegaWidth") = Round(Measure.ExtentsWidth,2)

iProperties.Value("PartA:1", "Project", "Stock Number") = _ 
iProperties.Value("PartA:1", "Custom", "MegaLength") & " X " & iProperties.Value("PartA:1", "Custom", "MegaWidth") 

 

Does that help you?  

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 4 of 29
andrew.warren
in reply to: MegaJerk

Looks like what I want at the part leve... Will this drill down from an assembly or does it have to be ran from each part? I want to run it at the assembly level and let it fill these out...

Andy Warren
BCDesign@bellsouth.net
Message 5 of 29

MegaJerk it looks like you did somehting similar in this post... http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/Run-ilogic-rule-in-each-part-from-the-... 

 

If I add my Custom prop iLogic to this will this do what I am talking about you think?

Andy Warren
BCDesign@bellsouth.net
Message 6 of 29

Something like this?

 

Dim openDoc As Document
openDoc = ThisDoc.Document

Dim docFile As Document 

If openDoc.DocumentType = 12291 Then

	For Each docFile In openDoc.AllReferencedDocuments
	
		If docFile.DocumentType = 12290 Then
		
		
			Dim FNamePos As Long
            FNamePos = InStrRev(docFile.FullFileName, "\", -1)	
						         
            Dim docFName As String
            docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
			
			If iProperties.Value(docFName, "Custom", "THICKNESS")="" Then
		
				iProperties.Value(docFName, "Custom", "THICKNESS") = Measure.ExtentsHeight 
				
			
			If iProperties.Value("Custom", "WIDTH")="" Then
				
				iProperties.Value("Custom", "WIDTH")= Measure.ExtentsWidth 
				
			If iProperties.Value("Custom", "LENGTH")="" Then
				
				iProperties.Value("Custom", "LENGTH")= Measure.ExtentsLength
						
			End If
		
		End If 
		
	Next
	
	Else
	
	MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exc​lamation)
	
End If 

 

Andy Warren
BCDesign@bellsouth.net
Message 7 of 29
MegaJerk
in reply to: andrew.warren

The code that I posted should be ran from the assembly, and works. Did you actually try using it? Is the problem now that you would like to update all of the parts (and in turn : iProperties) that are in the assembly ?

The code you last posted could work with some tweaking, but I don't believe that it will work in that current state.  



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 8 of 29

I guess I will also have to tell it to create the custom prop if it does not exist...

Andy Warren
BCDesign@bellsouth.net
Message 9 of 29

Hi andrew.warren,

 

Here is some information on creating the custom prop if it does not exist:

http://inventortrenches.blogspot.com/2011/05/use-ilogic-to-add-and-use-custom.html

 

Also just a heads up, I took a couple of minutes to look at your overall goal, an noticed that Measure.ExtentsHeight runs on the top level assembly (and therefore gathers it's height) even when iterating through the assembly components via the For Each. Unfortunately I didn't find a solution, but will post back I think of something.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com


 

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document

For Each docFile In openDoc.AllReferencedDocuments		
	'format  file name		
	Dim FNamePos As Long
	FNamePos = InStrRev(docFile.FullFileName, "\", -1)		         
	Dim docFName As String	
	docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)       

	customPropertySet = docFile.PropertySets.Item _
	("Inventor User Defined Properties")

	'check for custom iprops and add them if not found
	Try
		prop1 = customPropertySet.Item(“Thickness")
		prop2 = customPropertySet.Item(“Width")
		prop3 = customPropertySet.Item(“Length")
	Catch
	' assume error means not found
		customPropertySet.Add("", “Thickness")
		customPropertySet.Add("", “Width")
		customPropertySet.Add("", “Length")
	End Try

	'get value from model
	prop1.value = Measure.ExtentsHeight
	prop2.value = Measure.ExtentsWidth 
	prop3.value = Measure.ExtentsLength
	
Next	

 

Message 10 of 29

Yes that is what I want ti to to do, measure each part and return the part info into custom iprops as you created them. Dang, I did not want ti grabbing the assembly...

Andy Warren
BCDesign@bellsouth.net
Message 11 of 29

Ok between this, the three installs and the Subscription / additional seat order I am trying to place I have really screwed something up...

 

If I can not get it to work in the assembly I am fine with going into each part and running it. I want ti to create the custom props if they do not exist then get the Length Width and Thickness. Just as you had in the Assembly but I want ti to run in the part now. I tried to modify the code but ti was like trying to untangle Christmas tree lights blindfolded with all the people coming and going from my desk.

 

I am not even sure why we/they use the Custom but this is my third week here...

 

Any help is greatly apprciated!

Andy Warren
BCDesign@bellsouth.net
Message 12 of 29

Does this look correct?

 

I think I got it...

 

'check for custom iprops and add them if not found
Dim propertyName1 As String = "Length"
Dim propertyName2 As String = "Width"
Dim propertyName3 As String = "Thickness"


customPropertySet = ThisDoc.Document.PropertySets.Item _
("Inventor User Defined Properties")


Try
          prop = customPropertySet.Item(propertyName1)
          prop = customPropertySet.Item(propertyName2)
		  prop = customPropertySet.Item(propertyName3)
Catch
      ' Assume error means not found
            customPropertySet.Add("", propertyName1)
          customPropertySet.Add("", propertyName2)
		 customPropertySet.Add("", propertyName3) 
End Try


'output the custom iproperties and update the file
RuleParametersOutput()
InventorVb.DocumentUpdate()




iProperties.Value("Custom", "Length") = Measure.ExtentsLength
iProperties.Value("Custom", "Width") = Measure.ExtentsWidth
iProperties.Value("Custom", "Thickness") = Measure.ExtentsHeight



'update file
iLogicVb.UpdateWhenDone = True


 

Andy Warren
BCDesign@bellsouth.net
Message 13 of 29

Hi andrew.warren,

 

What you have works, but I noticed an issue that might trip you up.

 

If the iprops are checked and added as a group, it could cause an error if one of them exists but the others don't. So here's a version that checks/adds them one at a time. I've also added the measure extents to the check/add step, so that it just fills in the value as it the iProperty is checked/created.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com


 

 

Dim docFile As Document
docFile = ThisDoc.Document

customPropertySet = docFile.PropertySets.Item _
("Inventor User Defined Properties")

'check for custom iprop and add if not found
Try
    customPropertySet.Item(“Thickness").Value = Measure.ExtentsHeight
Catch
' assume error means not found and add
    customPropertySet.Add(Measure.ExtentsHeight, “Thickness")
End Try

'check for custom iprop and add if not found
Try
    customPropertySet.Item(“Width").Value = Measure.ExtentsWidth  
Catch
' assume error means not found and add
    customPropertySet.Add(Measure.ExtentsWidth, “Width")
End Try

'check for custom iprop and add if not found
Try
    customPropertySet.Item(“Length").Value = Measure.ExtentsLength
Catch
' assume error means not found and add
    customPropertySet.Add(Measure.ExtentsLength, “Length")
End Try

 

Message 14 of 29

I'm going to add this just in case someone might find it helpful, or in case this can be used to find a solution to getting the size for each component in the assembly. This rule does pretty much the same thing the other does, but as written it writes the extents info all to one custom iProperty named Size (example: Size: 0.3 in. x 0.3 in.  x 0.3 in.) It also formats the length of the size string. (example: 0.25 becomes 0.3 in. )

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com


 

'check for custom iprops and add them if not found

Dim propertyName1 As String = "Size"

customPropertySet = ThisDoc.Document.PropertySets.Item _
("Inventor User Defined Properties")

Try
	prop = customPropertySet.Item(propertyName1)

Catch
      ' Assume error means not found
	customPropertySet.Add("", propertyName1)

End Try

' Get the active document. This assumes it is a part document.
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

Dim oBox As Box
oBox = oPartDoc.ComponentDefinition.SurfaceBodies.Item(1).RangeBox


	'set IncludeLeadingDigit option
	'optional
	'use TriState.True to return a number such as 0.123
	'use TriState.False to return a number such as .123
	'use TriState.UseDefault to use the computer's regional settings
	LeadZero = TriState.True
	
	'set NumDigitsAfterDecimal option
	'optional
	DecNum = 1
	
	'set UseParensForNegativeNumbers
	'optional
	'use TriState.True to return a negative number as: (49.123)
	'use TriState.False to return a negative number as: -49.123
	'use TriState.UseDefault to use the computer's regional settings	
	NegFormat = TriState.False
	
	'set GroupDigits to include group delimiter specified (as specified in the locale settings)
	'optional
	'use TriState.True to return a number as: 1,234 (where comma is the locale setting)
	'use TriState.True to return a number as: 1234
	'use TriState.UseDefault to use the computer's regional settings
	GroupDigits = TriState.False 


Length1 = (oBox.MaxPoint.X - oBox.MinPoint.X) * 0.394 '& " in."
Width1 =(oBox.MaxPoint.Y - oBox.MinPoint.Y) * 0.394 '& " in."
Thickness1 = (oBox.MaxPoint.Z - oBox.MinPoint.Z) * 0.394 '& " in."


Length = FormatNumber(Width1, DecNum, LeadZero, NegFormat, GroupDigits)
Width = FormatNumber(Length1, DecNum, LeadZero, NegFormat, GroupDigits)
Thickness = FormatNumber(Thickness1, DecNum, LeadZero, NegFormat, GroupDigits)
	'MessageBox.Show("Extents = " & Thickness & " in. x " &  Length & " in.  x " &  Width & " in. " , "Title")
	iProperties.Value("Custom", "Size") = Thickness & " in. x " &  Length & " in.  x " &  Width & " in. " 

 

Message 15 of 29

This is really what we wanted but we want the longest dim in x,y or z to be length, then the next longest plane to be width and then the longest int the last plane to be thickness. Any ideas their?

Andy Warren
BCDesign@bellsouth.net
Message 16 of 29

I guess I could just return these results to a list then say the longest = L next longest = width and shortest = thick?

Andy Warren
BCDesign@bellsouth.net
Message 17 of 29
mehatfie
in reply to: andrew.warren

Would Opening each part and setting it to the current Active part not allow you to take the appropriate measurements?

 

You could open the part, do what you wish, then update, save, and close each part as it iterates through them.

 

Example:

 

 

docName = ThisDoc.Path  &  "\"  &  "Part Name"  &  ".ipt"

 

doc = ThisApplication.Documents.Opne(docName, True)   <  True sets the part to be the current active document

 

doc.Update()

 

///////////////////   Do what you'd like  /////////////

 

doc.Save()

doc.Close()

Message 18 of 29
andrew.warren
in reply to: mehatfie


So far Murphy is kicking my butt again, between licensing, Meetings with IT about Licensing and etc, I have not gotten this done...

 

Here is what I have so far...

 

I can create the parameters in the parts but I have not gotten the iLogic to drill down from the assembly level. I also need to return those values to a list then sort them by size so the Length = Longest measured Bounding box plane, Width = the next and then Thickness =  the shortest measured plane.

 

I am having a ahrd time getting all three of these to work in the same code? Any ideas?

Andy Warren
BCDesign@bellsouth.net
Message 19 of 29
theo.bot
in reply to: andrew.warren

I've tried the same workflow to automate, but its hard to do such thing. But i have used a differend way:

Create a (external) rule that loops tru your occcurenses, edit the occurense, add an ilogic rule in that occ (part), then return from edit.

In the rule that you create you can check or create the iprop and fill them with the measurement values.

I did this action for a model and it saves me vour ours work. I have to look up that code an will try to post it later.

Kind regards

Message 20 of 29
Q-Bixx
in reply to: theo.bot

I have implemented this rule but i'm stumbling upon an exception of use for this rule.

Suppose you have created your part with the use of "Make Components", nothing wrong with that but, ... (And this is where i have found the "exception", if your part is not designed perpendicular to at least 2 of the axis X,Y or Z, you get wrong results.

 

An example:

 

Suppose picture below (you'll get the idea instantaneously 😉 )

 

001.JPG

 

Now according to common sense my bounding box should be 10 x 50 x Height, but when i apply the rule to this part, my bounding box becomes :

 

002.JPG

 

Any ideas on how to overcome this?

Change UCS on demand of the Bounding Box?

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

Post to forums  

Autodesk Design & Make Report