iLogic to import Model Parameters to dwg Iproperties.. for beginners

iLogic to import Model Parameters to dwg Iproperties.. for beginners

Anonymous
Not applicable
2,456 Views
11 Replies
Message 1 of 12

iLogic to import Model Parameters to dwg Iproperties.. for beginners

Anonymous
Not applicable

Ok guys, I'd like to start by saying this is my first dive into iLogic. I haven't done any tutorials yet but just dabbled on my own. Hopefully this gets easier after more reading and some guidance. I know a touch of C++ and this is somewhat foreign to me. 

 

Anywho, here is what I am trying to accomplish. 

I have a model with a few parameters. I need to show these values in a table in a dwg. Thus far it's being done with a symbol and prompted entry, to where I have to manually enter all of the data that is already a parameter in the model file. I am trying to automate this process. What I think needs to happen is as follows-

-Model gets loaded as base view

-iLogic is run; takes model's user parameters and converts them to custom iProperties in the dwg file. 

-iLogic then takes this info, generates a table and spits out all of the parameters for you

 

Easier said than done for someone who doesn't computer good. Here is what I have so far (dont laugh)

 

SyntaxEditor Code Snippet

iProperties.Value("Custom", "Y1")= Parameter("Test Tube two.ipt.y1")
iProperties.Value("Custom", "Y2")= Parameter("Test Tube two.ipt.y2")
iProperties.Value("Custom", "Y3")= Parameter("Test Tube two.ipt.y3")
iLogicVb.UpdateWhenDone = True

(btw, i have no idea what the last line of code does)

This works fine for the above, although I have to run the rule after every edit to the parameters in my model file; using this i get the custom iproperties I want and have them displayed in a table, but i have to create the custom properties first in a template. 

 

Here is my first snag of many to come- the code doesnt know what to do when I upload a different model to the dwg. Say I upload filename "test tube 3", then the rule still searches for "Test Tube two" and returns value 0.0 for all of these parameters. Is there a way to assign the current loaded model's filename to a variable (String maybe?) that replaces "Test Tube two.ipt" in the above code, such that each model gets scanned, and the code will retrieve data from the current loaded model? I am building a template and want to be able to load any model with these parameters to it without having to re-write code every time. 

 

Snag 2- This should be a loop, where "test tube two" would be replaced by a function of some variable-

 

 

 

string prop = "y[i]"; //property y1,y2 etc iterates
string fname = *some code that retrieves current model filename*; //declaring variable equal to loaded model filename
for(int i=1; i<=*some model parameter from loaded model*, i++){ //loop to retrieve all parameters within given range
iProperties
.Value("Custom", prop)= Parameter("fname.ipt.prop") // sets custom property equal to filename parameter
} endl;

or something like that.. excuse my poor programming. I could never be software guy. I suppose I just dont know the syntax/VBA.

 

TL;DR

How do I set up the first code posted to read ANY model that's loaded, not just the one that's been hard coded?

How do I set up the loop to iterate like above?

 

Thanks for your time,

D.M.

0 Likes
Accepted solutions (2)
2,457 Views
11 Replies
Replies (11)
Message 2 of 12

MechMachineMan
Advisor
Advisor

Can you post a sample of what it looks like if you were to insert the table manually?

 

Also, can you tell us what the table is? Is it locations of holes? Configurations of things? etc.?

 

Also, UpdateWhenDone is a "parameter function" in iLogic, and you can read up more about it here:

https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2014...

 

Autodesk has a lot of documentation out there, so googling what you are looking with "+ autodesk" and then looking for links that are at "knowledge.autodesk.com" usually returns good results.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 12

Anonymous
Not applicable

Thanks for the prompt response, MechMachineMan.

Attached is a snip of a dummy table. It's actually a custom symbol for tube data and it prompts us to enter each data point.

 

I made some progress! I figured out you can use variables as an argument in iLogic (baby steps here). here is what it looks like so far -

 

Dim i As Integer 'declaring, will be iterating variable
i=1

Dim prop_y = "y"&i 'declaring property names
Dim prop_b = "b"&i 'all of these properties were created manually in my dwg
Dim prop_c = "c"&i 'its a template dwg so no big deal to do it manually

iProperties.Value("Custom", prop_y)= Parameter("Test Tube two.ipt", prop_y) 'now we can iterate!
iProperties.Value("Custom", "Y2")= Parameter("Test Tube two.ipt.y2") 'at least, this part has that capacity now
iProperties.Value("Custom", "Y3")= Parameter("Test Tube two.ipt.y3")
iProperties.Value("Custom", "b1")= Parameter("Test Tube two.ipt.b1")
iProperties.Value("Custom", "b2")= Parameter("Test Tube two.ipt.b2")
iProperties.Value("Custom", "b3")= Parameter("Test Tube two.ipt.b3")
iProperties.Value("Custom", "c1")= Parameter("Test Tube two.ipt.c1")
iProperties.Value("Custom", "c2")= Parameter("Test Tube two.ipt.c2")
iProperties.Value("Custom", "c3")= Parameter("Test Tube two.ipt.c3")
iLogicVb.UpdateWhenDone = True 'now I know what this means. thanks MechMachineMan!

MessageBox.Show(prop_y) 'spitting out names just to cerify my sanity
MessageBox.Show(prop_b)

Still a ways to go, but it's better than it was. it populates part of the table and updates when run so that's going pretty well. All of the [iProperties.Value("Custom", "stuff")=Parameter("other stuff")] lines need to be replaced by a loop. Right now I need to work on how to tell the code what model to look in to find the parameters. Instead of "Test Tube two", a string should be used as an argument for parameter. lets call it "fname". this variable would then replace the hard-coded filename, so there would be something like-  

 

Dim i As Integer 'declaring, will be iterating variable
Dim fname As String 
i=1
'fname = *something that retrieves current loaded model filename*

Dim prop_y = "y"&i 'declaring property names
Dim prop_b = "b"&i 'all of these properties were created manually in my dwg
Dim prop_c = "c"&i 'its a template dwg so no big deal to do it manually

iProperties.Value("Custom", prop_y)= Parameter("Test Tube two.ipt", prop_y)'iProperties.Value("Custom", prop_y)= Parameter(fname, prop_y)

It's been commented out, but I need variable fname to be the filename of whatever model is currently loaded onto the dwg (or, at least the first model that was loaded, since there will be more than one). There's a few snippets in the rule interface that look helpful but im not to savvy on those. 

0 Likes
Message 4 of 12

MechMachineMan
Advisor
Advisor

Something along these lines should work...

 

Dim i As Integer
Dim fname As String 

oViewModelName = ThisApplication.ActiveDocument.ActiveSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName fname = System.IO.Path.GetFileName(oViewModelName)
Dim i As Integer =1
Dim oComplete AS Boolean = False
Do Dim prop_y = "y"&i 'declaring property names Dim prop_b = "b"&i 'all of these properties were created manually in my dwg Dim prop_c = "c"&i 'its a template dwg so no big deal to do it manually
Try iProperties.Value("Custom", prop_y)= Parameter(fname, prop_y)
iProperties.Value("Custom", prop_b)= Parameter(fname, prop_b)
iProperties.Value("Custom", prop_c)= Parameter(fname, prop_c)
Catch
oComplete = True
End Try
Loop Until oComplete = True

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 5 of 12

Anonymous
Not applicable

That looks better already.

 

What is the argument for the catch block? As in, what exception would trigger the oComplete to be set to true?

I assume I would simply need to add something like i=i+1 for iterative purposes after "end try", and then set the loop to stop when i is greater than some variable which is set to the number of parameters I want to import (or another parameter that included this when imported)

 

I wish I could do for loops like we do in C++, that would make this easy.

 

I'll give this a shot!

0 Likes
Message 6 of 12

MechMachineMan
Advisor
Advisor
Accepted solution

@Anonymous

 

The Try/Catch is an error handler. So basically, it will loop through the parameters (y1, y2, y3, ...) until it errors out, then it will exit the loop.

 

Also, you CAN do For loops. iLogic is just a vb.net environment, so pretty much anything that works in vb.net will work in the "iLogic" environment.

 

An example of a for loop to iterate through the USER parameters:

 

'For loop version.
For Each oUserParam in ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters If oUserparam.Name Like "y*" or oUserParam.Name like "b*" or oUserParam.Name like "c*" Then
MsgBox(oUserParam.Name)
End if Next

 

The version with the index properly added in...

Dim i As Integer
Dim fname As String 

oViewModelName = ThisApplication.ActiveDocument.ActiveSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName
fname = System.IO.Path.GetFileName(oViewModelName)

Dim i As Integer =1
Dim oComplete AS Boolean = False
Do
    Dim prop_y = "y"&i 'declaring property names
    Dim prop_b = "b"&i 'all of these properties were created manually in my dwg
    Dim prop_c = "c"&i 'its a template dwg so no big deal to do it manually
    
    Try
        iProperties.Value("Custom", prop_y)= Parameter(fname, prop_y)
        iProperties.Value("Custom", prop_b)= Parameter(fname, prop_b)
        iProperties.Value("Custom", prop_c)= Parameter(fname, prop_c)
    Catch
        oComplete = True
    End Try
i = i+1 Loop Until oComplete = True

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 7 of 12

Anonymous
Not applicable

Awesome! This takes care of the filename and iterating snags I ran into. you have been very helpful, sir.

 

Now I just need to create a custom symbol that will generate to the appropriate size with parameters in the updated dwg file. 

 

I noticed it takes a while to run; not a big deal considering how much faster this is than manual. Would it speed the loop up if I told it when to stop? as in, include a user parameter in the model file that states the size of my index, so that the loop doesnt try to go past this index? There are alot of placeholder parameters and this code reads through all of them (even if most of them are empty)

 

 

There's alot about inventor I dont know.. If I wanted to run this as a macro, can I just copy and paste this code into VBA editor and then put a user command in my ribbon for it? or would I have to create a macro to just fire off the Rule I've created? The reason I ask is because I want to share this functionality with everyone else in the company, and no one really knows how to use iLogic (myself included)

0 Likes
Message 8 of 12

MechMachineMan
Advisor
Advisor

I would GUESS that it might be the iLogic calls slowing it down. Try this version that replaces the iLogic iprop/param calls with direct API ones and let us know how the speed is:

 

This conversion also makes it easier to CONVERT to VBA, which you must do in order to run it as a macro.

To covert to vba:

- If you are assigning an object to a non-basic type (string, int, etc.) you MUST use the SET statement.

- Also split in-line declaration/assignment to multiple lines (Dim obool as Boolean = True will NOT work in VBA)

- After you do the top 2 items it *should* run. If it doesn't, there are likely calls that are exclusive to either iLogic or vb.net that you will need to convert into an appropriate VBA method.

 

SyntaxEditor Code Snippet
Sub main()
	
	Dim oDoc As Document
	oDoc = ThisApplication.ActiveDocument
	
	If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then MsgBox("Drawing Docs Only!"): Exit Sub
	If oDoc.ActiveSheet.DrawingViews.Count < 1 Then MsgBox("No Views Found on Active Sheet") : Exit Sub
		
	Dim oViewModel As Document
	oViewModel = oDoc.ActiveSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument

	Dim oModelParams As Parameters
	oModelParams = oViewModel.ComponentDefinition.Parameters

	Dim i As Integer
    i = 1
	
	Dim oComplete As Boolean = False
	
  On Error Resume Next
	Do
	    Dim prop_y = "y"&i 'declaring property names
	    Dim prop_b = "b"&i 'all of these properties were created manually in my dwg
	    Dim prop_c = "c"&i 'its a template dwg so no big deal to do it manually
	    
		Call SetCustomiProp(oDoc, prop_y, GetParamDisplayValue(oModelParams.Item(prop_y)))
		Call SetCustomiProp(oDoc, prop_b, GetParamDisplayValue(oModelParams.Item(prop_b)))
		Call SetCustomiProp(oDoc, prop_c, GetParamDisplayValue(oModelParams.Item(prop_c)))
		
		If Err.Number <> 0 Then
	        oComplete = True
		End If
	    i = i+1
	Loop Until oComplete = True
	
  Err.Clear
  On Error GoTo 0

End Sub

Sub SetCustomiProp(oDoc As Document, oiPropname As String, ByVal oValue As String)
	Dim oCustomDwgiProps As PropertySet
	oCustomDwgiProps = oDoc.PropertySets("Inventor User Defined Properties")
	
	On Error Resume Next
		oCustomDwgiProps.Item(oiPropname).Value = oValue
		
		If Err.Number <> 0 Then
			oCustomDwgiProps.Add(oValue, oiPropname)
		End If
	On Error GoTo 0
End Sub

Function GetParamDisplayValue(oParam As Parameter) As String
	
'Test: MsgBox(GetParamDisplayValue(ThisApplication.ActiveDocument.ComponentDefinition.Parameters.Item(1)))	
	
	Dim oUOM As UnitsOfMeasure
	oUOM = oParam.Parent.UnitsOfMeasure
	
	Dim oDatabaseUnits As String
	oDatabaseUnits = oUOM.GetDatabaseUnitsFromExpression(oParam.Expression, oParam.Units)
	
	Dim oUnitType As UnitsTypeEnum
	oUnitType = oUOM.GetTypeFromString(oDatabaseUnits)
	
	GetParamDisplayValue = oUOM.ConvertUnits(oParam.Value, oUnitType, oParam.Units) & " " & oParam.Units
End Function

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 9 of 12

Anonymous
Not applicable

I couldnt get the setcustompropiProp function to work as a macro (Looks like vb.net?)

 

here is what I did instead

 

sub import()

 

Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then MsgBox ("Drawing Docs Only!"): Exit Sub
If oDoc.ActiveSheet.DrawingViews.Count < 1 Then MsgBox ("No Views Found on Active Sheet"): Exit Sub

'get iproperty collection object for current document
Dim iPropCollection As PropertySet
Set iPropCollection = ThisApplication.Documents.Item(1).PropertySets.Item(4)

'get model reference
Dim oViewModel As Document
Set oViewModel = oDoc.ActiveSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument

'get model parameter set
Dim oModelParameters As Parameters
Set oModelParameters = oViewModel.ComponentDefinition.Parameters

Dim i As Integer
i = 1

Dim oComplete As Boolean
oComplete = False

On Error Resume Next
Do
Dim prop_y As String
prop_y = "y" & i 'declaring property names
Dim prop_b As String
prop_b = "b" & i 'all of these properties were created manually in my dwg
Dim prop_c As String
prop_c = "c" & i 'its a template dwg so no big deal to do it manually

'setting iproperty to model parameter.. yields cm units for some reason
iPropCollection.Item(prop_y).Value = ((oModelParameters.Item(prop_y).Value) / 2.54)
iPropCollection.Item(prop_b).Value = ((oModelParameters.Item(prop_b).Value) * (180 / pi))
iPropCollection.Item(prop_c).Value = ((oModelParameters.Item(prop_c).Value) * (180 / pi))

If Err.Number <> 0 Then
oComplete = True
End If
i = i + 1
Loop Until i = 10
Err.Clear
On Error GoTo 0

MsgBox iPropCollection.Count

End Sub

 

One major issue I'm having is that the units for the iproperties end up as cm and radians.. not sure why it's defaulting to that since the user parameters for the model file have units of inches and sections. i converted in the code but that's a bandaid IMO.. not sure how to fix that.

 

the other issue I'm having is that once the code is run, the iproperties will update as expected. however, they wont show up as the updated values in the table I've created. only when I open the custom Iproperties tab  and close it do these values update. Any input? 

 

I'd like it to then create a custom table with the new imported values, but that's far more ambitious. At the moment, we simply trim/extend the custom symbol to create the size table we want. 

 

TL;DR

1- why do my user parameters import into iproperties with different units?

2- why do I have to open the custom iproperties window for the symbol with text (formula in text box to iproperty) to update?

0 Likes
Message 10 of 12

MechMachineMan
Advisor
Advisor
Accepted solution

1. Because API calls for Parameters return in DATABASE UNITS. i.e. according to the units by which they are stored internally.

http://modthemachine.typepad.com/files/ipropertiesandparameters.pdf

 

2.  Because you don't tell it to update, and the next update is only triggered when you close the iProp window.

 

Just add in "oDoc.Update" before "End Sub".


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 11 of 12

Anonymous
Not applicable

I had a hunch it had something to do with how the data is stored. Thanks! Is there a good way to convert, short of multiplying like I have?

 

That was easy. haha can you tell I'm new to this?

0 Likes
Message 12 of 12

MechMachineMan
Advisor
Advisor

Where there's a question, there's likely a link to an answer on the google.

 

http://adndevblog.typepad.com/manufacturing/2012/06/get-the-display-value-of-the-parameter-in-invent...


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes