iLogic driven Parameter error (Not Defined)

iLogic driven Parameter error (Not Defined)

gconley
Advocate Advocate
511 Views
4 Replies
Message 1 of 5

iLogic driven Parameter error (Not Defined)

gconley
Advocate
Advocate

I am trying to add another New Parameter using iLogic.  I copied the same code that was used for the first one and modified a little, but on this one it is telling me Type 'ModelDocument' is not defined.

gconley_0-1658936762323.png

 

This is the code I am using.

 

Dim oModelDoc As ModelDocument = ThisDoc.Document
Dim userParams As UserParameters = oModelDoc.Parameters.UserParameters

Try
	parametro = oModelDoc.Parameters("Plant_Listing")
 Catch
 	iLogicVb.RunExternalRule("Parameter Plant Listing")
End Try

Can someone tell me why this one doesn't work.

0 Likes
512 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @gconley.  Which type of document are you trying to add a parameter to (PartDocument, AssemblyDocument, or DrawingDocument)?  If it is a PartDocument or AssemblyDocument, then you will need to step down into their ComponentDefinition first, then the Parameters are below that.  However, in a DrawingDocument, the Parameters are just under the DrawingDocument object in the API's structure.  ModelDocument is not a Type of object within Inventor's API.  It is a term used in a couple situations, but not by itself, to help point to a Document Type object that a DrawingDocument may be referencing.

Try it like this instead:

(This is just trying to find the specified parameter, and if it does not find it, it will run the rule.

If the variable 'parametro' is representing a local parameter within the local/active document, and you are trying to set its value from the parameter named "Plant_Listing", then we will need to change it a bit.)

 

Dim oModelDoc As Document = ThisDoc.ModelDocument
Dim userParams As UserParameters = oModelDoc.ComponentDefinition.Parameters.UserParameters
Try
	parametro = userParams.Item("Plant_Listing")
 Catch
 	iLogicVb.RunExternalRule("Parameter Plant Listing")
End Try

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

gconley
Advocate
Advocate

I tried you suggestion and it didn't work gave me another error.

 

gconley_0-1658940988204.png

 

On another note, this is the code that was used for creating the Parameter inside of an IDW.

 

Dim oDrawingDoc As DrawingDocument = ThisDoc.Document
Dim userParams As UserParameters = oDrawingDoc.Parameters.UserParameters

Try
	parametro = oDrawingDoc.Parameters("Plant_Listing")
 Catch
 	iLogicVb.RunExternalRule("Parameter Plant Listing")
End Try

I am currently trying to create the same Parameter inside of an IAM and IPT.  If possible, I would like to keep the codes similar.  Is it possible to modify this one to work with IAM and IPT files?

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

OK.  That explains it.  I thought you were starting this iLogic rule from a DrawingDocument, and trying to access either a part or assembly document being represented within a view of the drawing.  As I said, in a drawing the parameters are right under the document object (Document.Parameters), but in model documents (parts/assemblies), there is a component definition right under the document, then the parameters are under that component definition (Document.ComponentDefinition.Parameters).

Below is a version of this code that you can use on all 3 types of documents:

(It first gets the generic Document object, then checks its DocumentType.  Then defines the variable representing its UserParameters according to which type it is.  Then uses that variable in the Try...Catch block below.

Dim oDoc As Document = ThisDoc.Document
Dim oUParams As UserParameters
If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
	oUParams = oDoc.Parameters.UserParameters
ElseIf oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
	oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	oUParams = oDoc.ComponentDefinition.Parameters.UserParameters
End If

Try
	parametro = oUParams("Plant_Listing")
 Catch
 	iLogicVb.RunExternalRule("Parameter Plant Listing")
End Try

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

gconley
Advocate
Advocate

The last version of the code you gave works when I run it in and IDW,  but I am still getting and error when I run it for an IAM and IPT.

 

gconley_0-1658948814772.png

 

0 Likes