Determine if Parameter Exists in Each Document

Determine if Parameter Exists in Each Document

C_Haines_ENG
Collaborator Collaborator
1,341 Views
4 Replies
Message 1 of 5

Determine if Parameter Exists in Each Document

C_Haines_ENG
Collaborator
Collaborator

I have seen very similar questions posted everywhere, however I keep getting a "ComponentDefinition" error whenever i run the below code:

 

Sub Main()
	Dim oOpenDocs As DocumentsEnumerator = ThisApplication.Documents.VisibleDocuments
	For Each oDoc As Document In oOpenDocs
		
		If oDoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject
			
		Dim oParas As UserParameters = oDoc.Document.ComponentDefinition.Parameters.UserParameters
		Dim oPara As UserParameter

		Try
   	 		oPara = oParas.Item("Drawing Type")
		Catch
    		oPara = oParas.AddByValue("Drawing Type", "Part", UnitsTypeEnum.kTextUnits)
		End Try
			
		iLogicVb.RunExternalRule("AutoCAD Export.iLogicVb")
		End If
	Next
	
End Sub

 I understand the external rule command line required the full directory I have removed it just for this post, the AutoCAD Export vb code will read a parameter called "Drawing Type" to determine if its a part or assembly drawing. 

 

However on older iterations of my templates I have used different parameters.


Id like to check each drawing file thats open if "Drawing Type" paramter exists and if not create it, however everytime I run the rule it gives me this error: Public member 'Document' on type '_DocumentClass' not found.

 

Other posts suggest changing the command to ThisDoc.ActiveDocument but I fear this will just take the value of the first page and will not continuously do it for each drawing missing this parameter.

0 Likes
Accepted solutions (1)
1,342 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @C_Haines_ENG.  Since you are inspecting a drawing, there is no "ComponentDefinition" in the path of getting to its Parameters.  Just remove that from your line of code which is getting the parameters.

 

Dim oParas As UserParameters = oDoc.Parameters.UserParameters

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

C_Haines_ENG
Collaborator
Collaborator


Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

😕 Very frustrating. 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

I think I see something else that would be problematic, now that I give it another look.  Parameter names can not have spaces in them.  I usually put an underscore ("_") where I would normally have a space in my parameter names.  So try changing "Drawing Type" to "Drawing_Type".

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

C_Haines_ENG
Collaborator
Collaborator

Ah youre right im dumb, the Parameter doesnt even have an underscore in it.

 

Thank you.

0 Likes