Use iLogic to create assembly parameter

Use iLogic to create assembly parameter

Anonymous
Not applicable
947 Views
4 Replies
Message 1 of 5

Use iLogic to create assembly parameter

Anonymous
Not applicable

Please don't judge 😉 

 

Inventor Professional 2017

 

I'm not a programmer and basically get ilogic to work through google searches and trial and error!  I've update our assembly and ipt templates to include a "TEXTURE" parameter.  This is a true/false parameter.  I'd like to create ilogic to add this parameter to older files as needed.  I've got everything working in the part files but the assembly file is giving me an error.  Here's the portion of code that works for the part file to get the parameter added...

 

'add TEXTURE parameter if it doesn't exist
Try
'Change value of param
Parameter("TEXTURE") = "True"
Catch
'Create Param as it doesn't exist
Dim oUserParam1 As UserParameter
oUserParam1 = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByValue("TEXTURE", False, "BOOLEAN")
End Try

 In the assembly file the rule is getting hung up on this portion of the code and gives this error...

 

Error in rule: TEST NEW UPDATE IAM, in document: 87210.iam

 

Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

 

What am I doing wrong?  Obviously there's some programming language difference between a part file and an assembly file but I'm not nearly smart enough to know what it is.  Any help would be appreciated.

 

Thank You!

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

Mark.Lancaster
Consultant
Consultant

@Anonymous

 

Programming needs and questions should be posted in the Inventor Customization Forum for best results

 

https://forums.autodesk.com/t5/inventor-customization/bd-p/120

 

I will have the moderator relocate your posting.

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

0 Likes
Message 3 of 5

Anonymous
Not applicable
Oops, Thanks Mark.


0 Likes
Message 4 of 5

Scott_Stubbington
Advocate
Advocate
Accepted solution

Hello,

I copied your code, pasted it to a rule in an Assembly document and ran it, it worked for me.  I have also created an external rule, ran it in an assembly document and it was fine, I then tried using your rule in a Part document and it failed, same error result as you.

 

I have managed to Run the following code in both and Assembly and Part documents...

Sub Main
    Dim varPartDoc as PartDocument
    Dim varAssDoc as AssemblyDocument
    If ThisApplication.ActiveDocumentType = kPartDocumentObject Then
        varPartDoc = ThisDoc.Document
        'add TEXTURE parameter if it doesn't exist
        Try
            'Change value of param
            Parameter("TEXTURE") = "True"
        Catch
            'Create Param as it doesn't exist
            varPartDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("TEXTURE", False, "BOOLEAN")
        End Try
    Else If ThisApplication.ActiveDocumentType = kAssemblyDocumentObject Then
        varAssDoc = ThisDoc.Document
        'add TEXTURE parameter if it doesn't exist
        Try
            'Change value of param
            Parameter("TEXTURE") = "True"
        Catch
            'Create Param as it doesn't exist
            varAssDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("TEXTURE", False, "BOOLEAN")
        End Try
    Else:
        MsgBox("Wrong Document Type", vbOKOnly, "Incorrect Document type") ' this code could be wrong
    End If
End Sub

 

Scott

Message 5 of 5

Anonymous
Not applicable

Thank you Scott.  Works great!

0 Likes