Dynamically changing a referenced model

Dynamically changing a referenced model

rickzacher
Contributor Contributor
475 Views
4 Replies
Message 1 of 5

Dynamically changing a referenced model

rickzacher
Contributor
Contributor

I'm trying to find a way to have the model reference used in my .DWG rule be updated automatically when the model name changes. I use a "template" file with specific rules for when a view is turned on or off based on the solid model parameter. When I change the name of the model (save as), the parameter still references the "template" file name as shown. Is there a way to reference this parameter without having to manually update the code?

 

If Parameter("F-F Template.ipt.parameter_name") = Parameter("F-F Template.ipt.other_parameter_name") Then
	ActiveSheet.View("VIEW4").View.Suppressed = True
Else
	ActiveSheet.View("VIEW4").View.Suppressed = False
End If
0 Likes
Accepted solutions (1)
476 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

If I am understanding the situation correctly, I believe this is possible.

However, if you have created the drawing view based on this template part file, then you did a save as and gave the new part file a different file name, that drawing view will still be representing the template model part.  You would most likely have to use something like the Manage tab > Modify panel > 'Replace Model Reference' tool to change the view from representing the template to representing the new part file.  After that step has been taken care of, then your code could create a Document type variable, then set its value by first getting the DrawingView object, then get its DrawingView.ReferencedDocumentDescriptor.ReferencedDocument to get the Document object.  Then simply use the normal API route to access its Parameter(s) (Document.ComponentDefinition.Parameters.Item("ParameterName").Value).  Then since you have already captured the DrawingView object, you can just use that variable to suppress or un-suppress the view, depending on the value comparison.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Here is an example of what the code could look like, if the file reference thing is correct.

oView = ActiveSheet.View("VIEW4").View
Dim oRefDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim oPDoc As PartDocument = oRefDoc
	oParams = oPDoc.ComponentDefinition.Parameters
	oParam1 = oParams.Item("parameter_name")
	oParam2 = oParams.Item("other_parameter_name")
	If oParam1.Value = oParam2.Value Then
		oView.Suppressed = True
	Else
		oView.Suppressed = False
	End If
End If

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 5

rickzacher
Contributor
Contributor

This worked perfectly. I created a "test" drawing file and model file and used the "replace model reference" tool in the ribbon and ran it through a few different changes. Works like a champ. I actually have another rule that will need this same set of code. I really appreciate your help with this!

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Good to hear.

I believe the 'replace model reference' task can also be automated with code too, but of course you have to have a plan for specifying the other model that is to replace it, which isn't always something easily done by code without user interaction of some sort, which of course would nearly eliminate the advantage of trying to automate it.

The DrawingView.ReferencedDocumentDescriptor gives you a DocumentDescriptor object.  That object has a Property called ReferencedFileDescriptor, which will return a FileDescriptor object.  That object has a method called ReplaceReference, which will allow you to specify the full file name of the file to replace the existing one.  It won't automatically bring up an interactive file dialog though, so you have to either include your own file dialog code to use, or just have that full file name handy in a variable to use there.  Also, if you look into the link for that method, it says the two files must have common ancestry, or it might encounter problems.  This is common though, even when done manually.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes