Drawing properties to referenced models properties

Drawing properties to referenced models properties

mikejones
Collaborator Collaborator
586 Views
5 Replies
Message 1 of 6

Drawing properties to referenced models properties

mikejones
Collaborator
Collaborator

Hi all

I have a need to take a custom iproperty from a drawing; the drawing number in this case, and copy it to a custom iproperty called "Drawing" in all models  that are referenced in the drawing views. The views may contain an assembly drawing and a number of additional views of the component parts required for assembly. I'm not looking to go deeper than top level model in each of the views.  Any help appreciated.

 

Mike

Autodesk Certified Professional
0 Likes
Accepted solutions (1)
587 Views
5 Replies
Replies (5)
Message 2 of 6

clutsa
Collaborator
Collaborator

Give this iLogic a try

Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument
Dim docM As Document

For Each oView In doc.ActiveSheet.DrawingViews 'look at each view
	If oView.ParentView Is Nothing Then 'if it's a base view
		docM = oView.ReferencedFile.ReferencedDocument 'grab the base component
'set the iProperty iProperties.Value(docM.DisplayName, "Custom", "Drawing") = iProperties.Value("Project", "Part Number") End If Next
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 6

mikejones
Collaborator
Collaborator

Thanks for the reply but I'm getting an error message when I run it; see below

 

Error in rule: DrawingNumberToModel, in document: HGF1000 - 03-01-01 PHTM

Object reference not set to an instance of an object.

 

I know it's getting the model names ok because I put a message statement before the iProperties.Value statement so there must be something wrong with the line that is copying the iProperties over to the model.

 

Any ideas?

Autodesk Certified Professional
0 Likes
Message 4 of 6

clutsa
Collaborator
Collaborator
Accepted solution

My guess is the display name has been overridden. Try this

Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument
Dim docM As Document

For Each oView In doc.ActiveSheet.DrawingViews 'look at each view
	If oView.ParentView Is Nothing Then 'if it's a base view
		docM = oView.ReferencedFile.ReferencedDocument 'grab the base component
                'set the iProperty
		docName = Right(docM.FullDocumentName, Len(docM.FullDocumentName) - InStrRev(docM.FullDocumentName,"\"))
		'MessageBox.Show(docName, "Title")

		iProperties.Value(docName, "Custom", "Drawing") = iProperties.Value("Project", "Part Number")
	End If
Next

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 5 of 6

mikejones
Collaborator
Collaborator

That is perfect, thanks Clutsa for your help. When I wrote some code myself I went along the same lines as the first lines you sent but without success, this new one works perfectly. I'm still not sure why the original code didn't work though

 

Thanks again

 

Mike

Autodesk Certified Professional
0 Likes
Message 6 of 6

clutsa
Collaborator
Collaborator

Someone changed the display name of model... if it doesn't look like someone changed the display name they may have changed it buy typing the part number in as the display name. Slow click to edit the name, delete the entire name, then press enter and the default name will come back. 

 

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes