iLogic and Custom iProperties

iLogic and Custom iProperties

douthett
Collaborator Collaborator
3,471 Views
13 Replies
Message 1 of 14

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
3,472 Views
13 Replies
Replies (13)
Message 2 of 14

Vladimir.Ananyev
Alumni
Alumni

I've reformatted your code:

 

Dim oCustProp As Inventor.Property 
iProperties.Value("Custom","Critical") = False 

if iProperties.Value("Custom","Critical") = True Then 
	'never happen because the property "Critical" value is always False
Else 
	iProperties.Value("Custom","Critical") = False 
End if 

You set the property value to False and never change it.

That's why you always see False.

 

 

You may consider the following code snippet.  

If the property exists, its current value would be shown in the message box.

Otherwise the property will be created with the value = True.

 

Try
	oProp = iProperties.Value("Custom","Critical")
' exists MsgBox("oProp = " & oProp) Catch MsgBox("oProp is absent. Let's create it." ) Dim Newvalue As Boolean = True iProperties.Value("Custom","Critical") = Newvalue End Try

 cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 14

douthett
Collaborator
Collaborator

Sorry I didn't get back to you until now but I had a hot project that I had to get done.

 

I inserted you code into my rule and I think I screw up.  after i close my rule I get this message oProp = False

 

Not sure what I did. 

 

Any new file will have Critical preset as False.

Pre-existing files will be missing the Critical iProperties

We need to be able to change Critical to say True and not have it change back to False

0 Likes
Message 4 of 14

Vladimir.Ananyev
Alumni
Alumni

You may consider the following variant. 

First this rule updates the mass and then updates or create properties  that should exist both in parts and assemblies. 

Property “Critical” is created only if it does not exist otherwise it is left as is.

'This rule can be executed as an external rule

'reference to the active document
Dim oDoc As Inventor.Document = ThisDoc.Document

'--- Actions applied to any document type

' set mass units = kg
oDoc.UnitsOfMeasure.MassUnits = UnitsTypeEnum.kKilogramMassUnits

'update mass and save it in the custom property "NetWeight"
ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
mass = iProperties.Mass
iProperties.Value("Custom", "NetWeight") = Round(mass, 3)

iProperties.Value("Custom","WeightUOM") = "KG"
iProperties.Value("Custom","ModelCode") = "Comp"
iProperties.Value("Summary","Company") = "JOY GLOBAL"

' set property 'Critical'
Try
	oProp = iProperties.Value("Custom","Critical")
    'property 'Critical' exists, do not change its value
Catch
	'property should be created with the default value False
	iProperties.Value("Custom","Critical") = False	
End Try


'--- Actions that depend on the document type

If TypeOf oDoc Is PartDocument Then
	'actions specific for the part document


ElseIf TypeOf oDoc Is AssemblyDocument Then
	'actions specific for the assembly document
	PNumber = iProperties.Value("Project", "Part Number")
	iProperties.Value("Custom", "RawMaterialDescription") = "BOM " & PNumber
	
	'place here other actions
	
End If

'Run Update
iLogicVb.UpdateWhenDone = True

MsgBox("iProperties were Updated")

I hope it meets your requirements (or at least close to them).


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 14

douthett
Collaborator
Collaborator

And I'm back to the same problem.  DC changes it from a Yes/No style text to a straight Text.

 

I'm being to think that it's not possible to do what I need it to do.

 

Thanks for trying

0 Likes
Message 6 of 14

Anonymous
Not applicable

Nothing is impossible.

Please try to describe better what you need to do.

0 Likes
Message 7 of 14

douthett
Collaborator
Collaborator

What we want is when we save a file it will check to see if the custom iproperty Custom is there.

If the iproperties we want it to add it to the file with it defaulted to say No/False

If it is there we want it to leave the ipropertry along and not make any changes to it

 

Critical must in Boolean text style, ie Yes or No since that is how we have that field set up in Vault.

0 Likes
Message 8 of 14

MechMachineMan
Advisor
Advisor
What do you mean "DC"?

--------------------------------------
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 9 of 14

douthett
Collaborator
Collaborator

DC is Autodesk Design Checker which is an app that checks parts, assemblies and drawings in Inventor

 

https://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Ainven...

 

0 Likes
Message 10 of 14

Vladimir.Ananyev
Alumni
Alumni

iProperties support four data types:  String, Date, Double and Boolean.

The following iLogic rule creates two custom properties that looks similar in the UI but are very different in their types:

 

' result - boolean

iProperties.Value("Custom", "Bool_1") = True

 

' result - text

iProperties.Value("Custom", "Bool_2") = "Yes" 

 

iProps Dialog.PNG

 

I made a quick test with the Design Checker and it looks like it recognizes Boolean type correctly.

In this window I defined Bool_1 property  of Boolean type with the default value False.

 

Design Checker.png

 

Could you please verify your check for the Boolean custom iProperties in the Design Checker?

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 11 of 14

douthett
Collaborator
Collaborator

I've tried that and I get an error message.

 

DC error.jpg

 

 

I just remembre why we get this error.  It's becasue the new files already have Critical set to a Boolean and Design Checker doesn't like it.  Don't know the fix for this

0 Likes
Message 12 of 14

Vladimir.Ananyev
Alumni
Alumni

Could you post the screenshot of the Design Checker window where the check for this iProperty was defined?  It looks like the definition requires text value, not boolean.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 13 of 14

douthett
Collaborator
Collaborator

There is not place in DC to tell it that the iproperty is Boolean

boolean.jpg

 

If we set the Values of True and False or Yes and No then it' throws up the error.  If we leave it blank then it sets the text style to Text.

 

It's a lose/lose situation, thats why we're trying to go with iLogic

 

0 Likes
Message 14 of 14

Vladimir.Ananyev
Alumni
Alumni

We need some time to analyze Design Checker internals.

I asked for help Rocky Zhang, the author of the Design Checker.

We will get back to you as soon as find some solution.

Thank you for  patience.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes