Add param value to active idw and template

Add param value to active idw and template

Anonymous
Not applicable
1,773 Views
11 Replies
Message 1 of 12

Add param value to active idw and template

Anonymous
Not applicable

 

I have the following code that allows the user to add a value to an existing multi value parameter in an idw. What I would like help on is to get this to also add the same value to the standard.idw template.

 

So after running this code on the current doc, it should open the Standard.idw file from the  template directory and run the same code, save and close the Standard.idw .

 

I can get it to add the value in the current file and open the standard.idw , but I cant figure out how to add the value to the standard.idw

 

any help is appreciated

 

newValue = InputBox("Enter a New Material", "iLogic", " ")
values = MultiValue.List("Material")

ValueCount = values.count

Dim MyArrayList(ValueCount) As String

For i = 0 To ValueCount

If i=ValueCount Then
    'Last value, add new one
    MyArrayList(i) = newValue
Else
    'add existing values to new array
    MyArrayList(i) = values(i)
End If

Next

MultiValue.List("Material") = MyArrayList

 

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

bradeneuropeArthur
Mentor
Mentor

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.Documents.open("your full file name of template ")

Your code

oDoc.save

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

0 Likes
Message 3 of 12

Anonymous
Not applicable

Hi & thanks!,

 

Yeah, I tried that, I can read an iprop from the standard.idw no probs; but I cant use the code to add a value to an existing multi value parameter in the standard. idw

 

...something obvious I'm sure

 

 

0 Likes
Message 4 of 12

Anonymous
Not applicable

still struggling with this

 

so basically, I want to open a drawing, then run a rule from that drawing. the rule will open a template idw and then add a value to an 'existing' multi-value parameter.

 

 

I've put a messagebox in the code that will show me the description of the template idw - this was done to see that I was communicating with the template ok - which it is...

 

however it simply wont add the entry to the multi value parameter.

 

If I omit the reference to the template file and run it on the drawing the rule is in, then it works fine-then entry is added....

 

any takers?

 

Dim Template As DrawingDocument
Template = ThisApplication.Documents.Open("C:\Inventor\Templates\Standard.idw")
newValue = "***TEST ENTRY***"
MessageBox.Show(iProperties.Value("Project", "Description"), "Title")

values = MultiValue.List("Material")

ValueCount = values.count

Dim MyArrayList(ValueCount) As String

For i = 0 To ValueCount

If i=ValueCount Then
    'Last value, add new one
    MyArrayList(i) = newValue
Else
    'add existing values to new array
    MyArrayList(i) = values(i)
End If

Next

MultiValue.List("Material") = MyArrayList

iLogicVb.UpdateWhenDone = True

Template.Save

0 Likes
Message 5 of 12

bradeneuropeArthur
Mentor
Mentor
Hi,

You are reading from the template and writing to the same template.
So that is why nothing will be added.

Are you familiar with programming, or not?

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

0 Likes
Message 6 of 12

Anonymous
Not applicable

if you had read my posts you would have noticed that I said I put that messagebox into TEST the code...

 

as I said, the code is reading from the template. but not writing.

 

If I remove the messagebox part, it does not write. I know this because I have tested it and the message box was put in at the end.

 

clearly, something is wrong, so I thought I would try and get some help from the forum... wrong decision evidently it would seem

 

I do not understand why people feel the need to reply to people in need of help.

 

Edited by
Discussion_Admin

0 Likes
Message 7 of 12

bradeneuropeArthur
Mentor
Mentor

@Anonymous

 

Hi,

 

Your reaction is I little bit overdone I think.

If your situation is that frustrating, I understand that of course.

 

But keep in mind:

There are always people willing to help and support, and so my intention also is.

 

So I will take your previous post and your comments as not personal, and I will not further comment it as you may understand.

 

If help is further appreciated, please let me know.

 

Hope you will solve the situation ASAP.

 

 

 

 

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

0 Likes
Message 8 of 12

MechMachineMan
Advisor
Advisor
Accepted solution

@Anonymous one of the limitations, AFAIK of iLogic is that it's difficult to directly communicate with another document that isn't referenced by the current document. In cases like this, it's better to use the API.

 

Please clarify, but my understanding is this: As a user is working on a new document, they may want to add a new value to your "template's list".. ie; if the template doesn't have 306SS, but they want to use that, they can add it in the current document. However, you want a system that will take their custom added value and push it back into the template for future use?

 

As @bradeneuropeArthur had mentioned, even your test code didn't reference a separate document, and from what I can tell, there are no specifiers anywhere to tell the code WHAT document's MultiValue parameters to look at, which becomes the issue.

 

Taking this into account, i programmed a solution through API. MultiValue lists through API are regarded as expression lists. Below is the code that should work.

 

@MjDeck I believe I found a bug or an oversight in the API -- The GetExpressionList function returns an array that just contains straight strings. In order to use the SetExpressionList with a Text parameter, the array needs to use the string surrounded by quotes, which seems like an inconsistency between the 2 features. As you can see in my code below, after fetching the Expression List (if it is text values), I have to iterate through the fetched list and add quotes to either side in order to again make it work in the SetExpressionList function. Thanks for checking it out.

 

Dim oSourceDoc As Document
oSourceDoc = ThisDoc.Document
newValue = """*TEST2*"""

Dim Template As DrawingDocument
Template = ThisApplication.Documents.Open("C:\Users\Desktop\Drawing1.idw", True)

Try
	oMValue = Template.Parameters("Matl")
Catch
	MsgBox("Error Getting MultiValue Param from Target Template Document!")
	Exit Sub
End Try

'Get and fill CURRENT array entries
Dim MyArrayList(oMValue.ExpressionList.Count - 1) As String
MyArrayList = oMValue.ExpressionList.GetExpressionList()

For i = 0 To UBound(MyArrayList)
	If Left(MyArrayList(i),1) <> Chr(34)
		MyArrayList(i) = Chr(34) & MyArrayList(i)
	End If
	
	If Right(MyArrayList(i),1) <> Chr(34)
		MyArrayList(i) = MyArrayList(i) & Chr(34)
	End If
Next

''resize array to add new values
ReDim Preserve MyArrayList(UBound(MyArrayList) + 1)
MyArrayList(UBound(MyArrayList)) = newvalue

'Loop to double check values in my array list
For i = 0 To UBound(MyArrayList)
	oStr = oStr & vbLf & MyArrayList(i)
Next
MsgBox(oStr)

'Push the value to the MultiValue List
oMvalue.ExpressionList.SetExpressionList(MyArrayList, True, 0)

Template.Save

'' These lines below work for adding new mvalue
'Dim MyArrayList(0) As String
'MyArrayList(0) = """Value"""

--------------------------------------
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 9 of 12

MjDeck
Autodesk
Autodesk
Accepted solution

@MechMachineMan, I'm not seeing that problem. In my tests, GetExpressionList() returns the items in quotes.
Maybe you initially created the expression list by calling SetExpressionList() with an array of string items, but each item was not within the two double quotes? That won't work very well. We should probably make it throw an error.
(Note: the two double quotes are there to allow for the future possibility of string functions in parameter equations.)

 

But in this case, you don't have to work with the individual items in the expression list through the API. @Anonymous can use his original code to add the value to the list in the current document. Then use the API to copy that list to the template. Rather than going through the items, just copy the whole list:

Dim sourceDoc As DrawingDocument = ThisDoc.Document
Dim sourceParam = sourceDoc.Parameters("Material")

...

Dim destinationParam = Template.Parameters("Material")

destinationParam.ExpressionList.SetExpressionList (sourceParam.ExpressionList.GetExpressionList())

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 10 of 12

MechMachineMan
Advisor
Advisor

@MjDeck You are correct, it is just a bug from adding it through SetExpression, which I did not notice originally. I did recreate the multi-value and the GetExpression did work fine right off the bat.

 

I tested adding a new one with this code, and it doesn't error out. It does also add it to the set, but will not display it in the drop down. The first portion of the rule I posted also allowed the same value to be added to the stored expression list multiple times (as viewed through the MsgBox), whereas through the API it just appears to ignore it if it's the same value.

 

Dim Template As DrawingDocument
Template = ThisDoc.Document

Try
	oMValue = Template.Parameters("Matl")
Catch
	MsgBox("Error Getting MultiValue Param from Target Template Document!")
	Exit Sub
End Try

Dim MyArrayList(0) As String
MyArrayList(0) = "plstc"

'Push the value to the MultiValue List
oMvalue.ExpressionList.SetExpressionList(MyArrayList, False, 0)

Template.Save

--------------------------------------
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

Perfect @MjDeck

 

works for me... thank you!

0 Likes
Message 12 of 12

MjDeck
Autodesk
Autodesk

@MechMachineMan, you should be able to get new values to display in the dropdown by setting the second argument of SetExpressionList to True.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes