Get UserParameter values for FormattedText in ModelState members.

Get UserParameter values for FormattedText in ModelState members.

AlexTRK
Explorer Explorer
530 Views
8 Replies
Message 1 of 9

Get UserParameter values for FormattedText in ModelState members.

AlexTRK
Explorer
Explorer

I'm trying to reference a UserParameter from FormattedText using the <Parameter> tag like this:

"<Parameter ComponentIdentifier='" & ThisDoc.Document.FullDocumentName & "' Name='UserParameter' Precision='2' ></Parameter>"

 Which works great for plain parts and assemblies but as soon as I try to get the value of a parameter from within a ModelState that isn't the [Primary] one, it fails.

 

I've created a simple part to demonstrate what's going on, if you run the rule from the active ModelState, it can't read the parameter but as soon as you select the [Primary] state it reads it just fine.

 

Manually adding it will show that the FormattedText references something called 'MemberDocs'

EX:

<Parameter Resolved='True' ComponentIdentifier='**C:\TestP.ipt*MemberDocs*xWuyhbddkK0o4dxyrKyf5npj0Rg*TestP.ipt<Model State1>' Name='UParm' Precision='3'>2.000</Parameter>

 

Is there any way to specify that member doc in the <Parameter> tag maybe?

 

Thanks

0 Likes
531 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

Hi @AlexTRK.  I haven't tried it quite the way you are talking about here, but you could create a String type variable on a previous line of code, and set its value the way you want it, then use that variable instead of the 'FullDocumentName' portion of code you are using in that line of code shown.  In that previous line of code, don't use the actual 'FullDocumentName', but instead use 'FullFileName', then add the "<YourModelStateName>" portion to the end of it, to specify the ModelState you want to target, instead of the one that is currently active in 'ThisDoc'.  Do you understand what I mean there?  When working with a 'model' type document, and ModelStates are involved, the property 'FullDocumentName' is basically just the FullDocumentName, immediately followed by the name of the ModelState that the document is currently under the influence of, and that ModelState name is within "<" & ">" brackets.  You could simply create your own String value to use, instead of using the document's 'active' value.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 9

AlexTRK
Explorer
Explorer

Thanks for your response, but I've tried a few combinations of this and haven't been able to get it to work properly.

"<Parameter ComponentIdentifier='...TestP.iptModel State 1' Name='DParm' Precision='2' ></Parameter>"
'...TestP.ipt Model State 1'

'...TestP.ipt (Model State 1)'

'...TestP.ipt <Model State 1>'
'...TestP.ipt\Model State 1'
'...TestP.ipt*Model State 1*TestP.ipt (Model State 1)'

All seem to either cause an 'Unspecified error' or end up just displaying as regular text.

0 Likes
Message 4 of 9

WCrihfield
Mentor
Mentor

Hi .  The best way to learn how to format it, is by reverse engineering & looking at examples.  For instance, you can use an 'InputBox' to show yourself the 'selectable' text of the value behind the FullDocumentName of a document, by putting that value in the 'DefaultResponce' portion of that line of code, like the following line of code.

a = InputBox("", "FullDocumentName", ThisDoc.Document.FullDocumentName)

Notice there is no space between end of the FullFileName portion, and ModelState name portion.

 

Now, with that in mind, we can create our own String type variable, and set its value the way we want it to be formatted, which is similar to the FullDocumentName from the above example, but instead of the ModelState name it is showing, we can put a different ModelState name in there, as long as that ModelState exists in the document.

 

Below is an example of what I was trying to tell you about.  Also notice that by default, when you first create a new ModelState using the mouse commands, there is a space between "Model" & "State", but there is no space between "State" & "1", unless you have renamed the ModelState differently than its default.  Spelling, capitalization, and spaces are critical.  First we create the variable here, and set its value as described.

Dim FDN As String = ThisDoc.Document.FullFileName & "<Model State1>"

Now use that 'FDN' variable in the following line, instead of how you were doing it before.

"<Parameter ComponentIdentifier='" & FDN & "' Name='UserParameter' Precision='2' ></Parameter>"

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 9

AlexTRK
Explorer
Explorer

Maybe it has something to do with my Inventor installation or how I'm creating the views but this code:

Dim oSheet As Sheet = ThisServer.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject).Sheets.Item(1)
Dim oPoint As Point2d = ThisServer.TransientGeometry.CreatePoint2d(10, 10)
Dim oView As DrawingView = oSheet.DrawingViews.AddBaseView(ThisDoc.Document, oPoint, 1, ViewOrientationTypeEnum.kRightViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
Dim oNote As GeneralNote = oSheet.DrawingNotes.GeneralNotes.AddFitted(oPoint, "")
Dim FDN As String = ThisDoc.Document.FullFileName & "<Model State1>" 'I've even tried 'ThisDoc.ActiveModelState' here is well.
oNote.FormattedText = "<Parameter ComponentIdentifier='" & FDN & "' Name='DParm' Precision='2' ></Parameter>"

 

 With these user parameters:

Params.png

 

 Creates this drawing:

Output.png

If we're referencing the document correctly now then it could be an internal bug... very strange.

0 Likes
Message 6 of 9

WCrihfield
Mentor
Mentor

I think I may see the problem now that I am seeing the entire code.  I think it is because you just created a new drawing document, and it has not been saved yet, so it will not have a value for FullFileName yet, and the term ThisDoc.Document' may be pointing to that new drawing document, instead of to the model document.  And even if it was pointing to the model document, if that has not been saved yet either, you will have the same problem...no value for FullFileName.  I have not messed with FormattedText contents for ModelState specific values much yet, so I'm not 100% sure if everything is stable there when the contents are created entirely by code yet.  Plus I'm still using 2022, so there may have been some updates in 2023 that I do not have available for testing.

 

What you may need to do, in order to get the FormattedText right, is to create it exactly the way you want it manually, using the Format Text dialog, and its nice tools made just for this, then retrieve the results by code, and look at its FormattedText contents.  If you use the InputBox trick I showed you above to do this, then you could copy/paste that results text back into your code to set the value properly...if what you are trying to do is possible.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 9

AlexTRK
Explorer
Explorer

Well at least I've learned something from this, I had no idea InputBox was a thing, I've been using MessageBox for my debugging but it's weird about selecting text.

 

Pulling the FormattedText from a note I create manually gets me:

<Parameter Resolved='True' ComponentIdentifier='**C:\TestP.ipt*MemberDocs*xWuyhbddkK0o4dxyrKyf5npj0Rg*TestP.ipt<Model State1>' Name='DParm' Precision='2'>4.00</Parameter>

Pasting that back into my code does the same thing as before. It's either a bug with ModelStates or there has to be some sort of very sneaky formatting issue.

 

As a side note I've found out that if you open an ipt file with 7Zip you can find that MemberDocs folder in there so it should be possible... eventually. 

Message 8 of 9

SašoPrijatelj
Advocate
Advocate

Hi,

 

Did anyone solve this? What does the string "xWuyhbddkK0o4dxyrKyf5npj0Rg" in the parameter example below represent in case if a parameter of a component in a model state is referenced in FormattedText on a drawing?

 

<Parameter Resolved='True' ComponentIdentifier='**C:\TestP.ipt*MemberDocs*xWuyhbddkK0o4dxyrKyf5npj0Rg*TestP.ipt<Model State1>' Name='DParm' Precision='2'>4.00</Parameter>

 

There is no trace of that string (which is probably some internal Model State ID?) in the ModelState object properties. It also does not change with a model state name but is unique for each model state.

 

Or to rephrase the question: how to programmatically reference a parameter from a component in non-primary Model State in a  text on a drawing?

 

 

 

 

-----------------------------------------------------------------------
AutoDXF - automatic flat pattern creation and batch export to DXF for Inventor

Please use "Accept as Solution" & give "Kudos" if this response helped you.
0 Likes
Message 9 of 9

WCrihfield
Mentor
Mentor

Hi @SašoPrijatelj.  I still do not know where that odd String value comes from, but did notice that it did seem to be consistent per ModelState name.  I have checked the 'InternalName' of the Document objects associated with each ModelState, but those are formatted differently.  I also checked the AttributeSets associated with each ModelState, but there were none.  I even guessed at a few possible 'hidden' property names, but none of them worked.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes