edit a parameter in a different part - autonumber storage counter-iLogic

edit a parameter in a different part - autonumber storage counter-iLogic

andrew_canfield
Collaborator Collaborator
755 Views
9 Replies
Message 1 of 10

edit a parameter in a different part - autonumber storage counter-iLogic

andrew_canfield
Collaborator
Collaborator

Hello,

Is there a way to use iLogic to update a parameter in a part (\top folder\count.ipt) given it's file path?

 

This parameter is used to hold a number - an external rule performs a save as (on a new file) reads the value from count.ipt, saves the file then add 1 to the parameter in count.ipt.

 

I had this working using Excel but it's throwing up a com error after a windows update..

 

Below is an external rule which loops saving a copy of the file you now have open. Reading the start number from an excel file (AutoNumberCounter.xlsx) - working before the windows update.

apologies - development code a bit messy..hopefully it provides a little more insight.

 

possibly replace 'AutoNumberCounter.xlsx' with 'count.ipt' - if the parameter can be edited?

 

 

'test rule to save as & increment number 
xx= ThisDoc.PathAndFileName(True)
yy = ThisDoc.Path
MessageBox.Show(xx, yy)
aa = ThisDoc.FileName(False) 
'without extension bb = number
bb = Right(aa, 5)
' extension 
EXT1 = Right(xx, 4)
dd = Left(aa, 12)
'################

'counter path
cp = Left(yy, 44)'copy the top folder location
an = cp & "AutoNumberCounter.xlsx"
ExNo = GoExcel.CellValue(an, "Sheet1", "A1")
ExNoS = CStr(ExNo)

'MessageBox.Show(an, ExNoS)
'####################


FrName = Left(aa, 12)
EdNameSt = Right(aa, 5)

Dim RepeatX As Integer 

RepeatX = InputBox("How Many", "Incremental Save", "2")
StartNo = ExNo
EndNo = ExNo + RepeatX

For ee = 1 To RepeatX	
	
'NameC6 = EdNameSt + ee
NameC6 = StartNo + ee

NameCt = "00000" & NameC6

EdName = Right(NameCt, 5)

'MessageBox.Show(EdName, NameCt)
	
'xx1 = ee
''yy1 = "00" & CStr(xx1)
'yy1 = CStr(xx1)
MessageBox.Show(xx, yy)
''mm = yy & "\" & bb & yy1 & cc 
''mm = yy & "\" & bb & dd & yy1 & cc

mm = yy & "\" & FrName & EdName & EXT1

'MessageBox.Show(mm, CStr(EdName))
ThisDoc.Document.SaveAs(mm, True)
Next
GoExcel.CellValue(an, "Sheet1", "A1") = EndNo
MessageBox.Show("Save the xlxs - pop up behind Inventor", "Remember")

 

 

 

 

Regards

 

Andrew

 

 

 

 

0 Likes
Accepted solutions (1)
756 Views
9 Replies
Replies (9)
Message 2 of 10

A.Acheson
Mentor
Mentor

You can reference the document you want to edit with link here

 

And for access to UserParameters link here and some of code for component definition from the sample here

UserParameter.Value() As Variant

oDoc = Documents.Open( FullDocumentName As String, [OpenVisible] As Boolean ) As Document

partDoc =
oDoc
' Get the UserParameters collection
Dim UserParams As UserParameters
UserParams = partDoc.ComponentDefinition.Parameters.UserParameters

Dim UserParam As UserParameter
UserParam = UserParams(“Enter Name Here”) 

UserParam.Value = UserParam.Value +1


 

Or alternately you should be able to use the ilogic snippet parameter reference here

 

 OParam=Parameter(partDoc.DisplayName,”Enter Parameter Name Here”).Value 

OParam=OParam+1 

 

 

 

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 10

andrew_canfield
Collaborator
Collaborator

Many thank but this creates an error, "Reference to a non-shared member requires an object reference."

The part holding the parameter will open but I can't 'tunnel' into it to edit the parameter value.

0 Likes
Message 4 of 10

A.Acheson
Mentor
Mentor

This works for me. 

 

Ensure the user parameter exist and that you have followed the same document reference down from when you opened this file. 

 

Dim oDoc As Document
oDoc = ThisApplication.Documents.Open("ENTER FULL FILE PATH HERE", True) 

Dim partDoc as PartDocument partDoc = oDoc ' Pass the object after opening to work with this part document ' Get the UserParameters collection Dim UserParams As UserParameters UserParams = partDoc.ComponentDefinition.Parameters.UserParameters Dim UserParam As UserParameter UserParam = UserParams(“Count”) 'Enter Parameter Name Here MessageBox.Show(UserParam.Value, "Count before adding") UserParam.Value = UserParam.Value + 1 MessageBox.Show(UserParam.Value, "Count after adding")    

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 10

andrew_canfield
Collaborator
Collaborator

Apologise, I'm pretty certain I've followed the instructions but.. 

Counter2.PNG

 

Thankyou for the assistance.

 

Regards

 

Andrew

0 Likes
Message 6 of 10

A.Acheson
Mentor
Mentor

Unless you have a variable elsewhere in your image you are looking for the wrong parameter name. The name if string should be "CounterValue"

 

AAcheson_0-1640276074066.png

 

This error should come up as 

AAcheson_2-1640276307552.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 10

andrew_canfield
Collaborator
Collaborator
Sorry, my bad, I was testing with an additional parameter called 'xyz' along side 'Countervalue' the text did read 'CounterValue' but the same error occurs.
0 Likes
Message 8 of 10

andrew_canfield
Collaborator
Collaborator

countervalue.PNG

0 Likes
Message 9 of 10

A.Acheson
Mentor
Mentor
Accepted solution

You are offering a variable rather than a string value. Hence the not declared error. 

AAcheson_0-1640280360739.png

 

 

String value has the quotes. 

Dim UserParam As UserParameter
UserParam = UserParams(“CounterValue”) 'Enter Parameter Name Here

 

If you want to use a variable string. 

Dim oName as String
Dim oName = "CounterValue"
Dim
UserParam As UserParameter UserParam = UserParams(oName) 'Enter Parameter Name Here

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 10 of 10

andrew_canfield
Collaborator
Collaborator
Excellent - many thanks 🙂
Enjoyed the test too - edited to: (there was an extra Dim-second line)
Dim oName As String
oName = "CounterValue"
Dim UserParam As UserParameter
UserParam = UserParams(oName) 'Enter Parameter Name Here

Thanks Again