iLogic and Custom iProperties

iLogic and Custom iProperties

douthett
Collaborator Collaborator
1,075 Views
12 Replies
Message 1 of 13

iLogic and Custom iProperties

douthett
Collaborator
Collaborator

Inventor 2014

 

I'm just starting to learn iLogic so I'm going to ask some stupid questions.

 

We need to add some custom iproperties to our files. Some files already has these iproperties and they're filled in; others do not. What I want is to have iLogic enter the missing iproperties and ignore the ones that are there and filled in.

 

What I've tried so far:

 

Dim oCustProp As Inventor.Property

iProperties.Value("Custom","Critical") = False

 

if iProperties.Value("Custom","Critical") = True Then

Else

iProperties.Value("Custom","Critical") = False

End if

 

The problem is that every time I save it changes the Critical iproperty back to False. What am I doing wrong? I've attached the reset of my codes to this threads. These work.

0 Likes
1,076 Views
12 Replies
Replies (12)
Message 2 of 13

douthett
Collaborator
Collaborator

I really hate how sometime Autodesk screws up my text.   When I wrote this I did have paragraghs so it would be easier to read

0 Likes
Message 3 of 13

MechMachineMan
Advisor
Advisor
DO you have the code set to run on an event trigger that is running the code?

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 13

douthett
Collaborator
Collaborator

I'm using the iLogic code inside of Design Checker.  It's triggered when I save the part/assembly

0 Likes
Message 5 of 13

MechMachineMan
Advisor
Advisor
So have your code written is telling it to write it as false every time.
It should be inside of an if statement if you want it to be conditional.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 6 of 13

douthett
Collaborator
Collaborator

ok so how do I do that?  I've rather clueless. 

0 Likes
Message 7 of 13

MechMachineMan
Advisor
Advisor
Dim oCustProp As Inventor.Property
iProperties.Value("Custom","Critical") = False ' THIS LINE IS NOT CONDTIONAL AND WILL THUS SET THE iPROP TO FALSE EVERY TIME.

if iProperties.Value("Custom","Critical") = True Then ' THIS WILL NEVER RUN AS IT IS ALWAYS SET TO FALSE ABOVE
Else
iProperties.Value("Custom","Critical") = False ' THIS WILL ALWAYS BE TRUE BECAUSE IT IS SET TO FALSE ABOVE
End if

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 8 of 13

douthett
Collaborator
Collaborator

So you're saying that there is no way to get a code to put in the custom iproperties if it's missing and to have it never change the value if it's different than the default.

 

Pleae remember I'm just leanring this.  It's been almost 25 yrs sicne I last programed

0 Likes
Message 9 of 13

MechMachineMan
Advisor
Advisor

If iProperties.Value("Custom","Critical") = <> "" 'If Critical Is Not Empty

          'Do Nothing

Else    'Otherwise

         iProperties.Value("Custom","Critical") = False     'It is obviously not critical and will thus be false
End if

 

Something like that might work for you. It might throw an error if the Critical Doesn't exist'; i'm not completely sure. But in that case, you would just need:

 

Try

If iProperties.Value("Custom","Critical") = <> "" 'If Critical Is Not Empty

          'Do Nothing

Else    'Otherwise

         iProperties.Value("Custom","Critical") = False     'It is obviously not critical and will thus be false
End if

Catch

        iProperties.Value("Custom","Critical") = False     'It is obviously not critical and will thus be false

End Try

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 10 of 13

Curtis_Waguespack
Consultant
Consultant

Hi douthett,

 

Here is an iLogic rule similar to what @MechMachineMan posted (his rule gave me an error, but the idea was directionally correct).

 

This rule is looking for a custom Text iproperty called Critical.

 

Try 'try to read the custom iproperty
    If iProperties.Value("Custom","Critical") = "" Then 'If Critical Is Empty
    'get user input
    oAnswer = MessageBox.Show("Is this critical?", "iLogic", _
    MessageBoxButtons.YesNoCancel)
        If oAnswer = vbCancel Then
        Return 'exit the rule
        Else If oAnswer = vbYes
        iProperties.Value("Custom","Critical") = "Critical"
        Else
        iProperties.Value("Custom","Critical") = "Not Critical"
        End If
    Else 'If Critical Is NOT Empty    
    'Do Nothing
    End if
Catch 'catch the error is the property doesn't exist
    MessageBox.Show("No custom iproperty named Critical found.", "iLogic")
End Try

 I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 11 of 13

douthett
Collaborator
Collaborator

Sorry I haven't replied until now.  Was on a HOT project.

 

I was looking at your code and the only problem I can see is that Critical needs to be in Yes/No type.

 

yes-no.png

 

Since the field is never empty... i don't think this would work.

 

Some of my early code would put in teh custom iproperties critical if it was missing but the problem was that if I changed it to say Yes (true) the code would change it back to No (false)

 

 

0 Likes
Message 12 of 13

Daren.Lawrence
Autodesk
Autodesk

Hi Amy,

 

Here's a slight twist on the code Curtis has to match what you've written in your reply:

 

'    for yes/no, you must define it as a boolean data type
    Dim bAnswer As Boolean
    'This will ask the user for input via a yes/no radio input box with default
    'set to "no"
    bAnswer = InputRadioBox("Is this Critical?", "Yes", "No", False, "iLogic")
        iProperties.Value("Custom", "Critical") = bAnswer
'''        You can add this to the Try/End Try code Curtis has given
'''         But if you're positive it's always going to be there, you can 
'''         also just use these few lines AS your iLogic code. I'd say that's
'''         a little dangerous though to be honest.

Daren


Daren Lawrence
Product Support Specialist
MFG Support - Inventor
Autodesk, Inc.


http://beinginventive.typepad.com/being-inventive/
0 Likes
Message 13 of 13

Daren.Lawrence
Autodesk
Autodesk

'    For yes/no, you must define it as a boolean data type

Dim bAnswer As Boolean = False 'default it to "No" or set to True for "Yes"

Try

Dim bExists As String ' If the custom property exists, we'll look at it as a string

'Report on current custom property value with a message box

bExists = iProperties.Value("Custom","Critical")

MessageBox.Show(bExists, "'Critical' Value?")

'Return        '**Or uncomment this "Return" and comment the line directly above if the

'dialog box gets annoying

Catch 'the Catch just says, "if there's an error" meaning, we'll write the

'property if it errors out and can't find the iProperty existing

   

    'This next part will ask the user for input via a yes/no radio input box

    'with default set to "no"

    bAnswer = InputRadioBox("Is this Critical?", "Yes", "No", False, "Critical?")

        iProperties.Value("Custom", "Critical") = bAnswer

End Try '3 elements needed: Try, Catch and End Try

   

' This is a way to do it from scratch by the sounds of what you want.

 

 

Daren



Daren Lawrence
Product Support Specialist
MFG Support - Inventor
Autodesk, Inc.


http://beinginventive.typepad.com/being-inventive/
0 Likes