Need to retrieve Type data of custom iPropertis using iLogic

Need to retrieve Type data of custom iPropertis using iLogic

RoyWickrama_RWEI
Advisor Advisor
4,035 Views
23 Replies
Message 1 of 24

Need to retrieve Type data of custom iPropertis using iLogic

RoyWickrama_RWEI
Advisor
Advisor

I am developing part of my rule to handle custom iProperties.

I need to retrieve "Type" data of iProperties.

Today.pngMy 

My current rule (sample) is attached here to: I need to do with iProperty type information.

I appreciate if someone help me.

0 Likes
Accepted solutions (2)
4,036 Views
23 Replies
Replies (23)
Message 2 of 24

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Do you need to know/read the type of a selected custom property or do you need to set/define the type of a custom property?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 3 of 24

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@RoyWickrama_RWEI,

 

Try below iLogic code to add custom properties depending on data type. Make sure that value is entered according data type.

 

For example:

Boolean - 'True - Yes' or 'False - No'

Date - 07-12-2018

Number - 123456

String - Any string value

 

Sub Main()

oRuleNo = "iL0080"



Dim X_PaintCode As String

X_PaintCode = "Paint Code"

Dim X_Size As String

X_Size = "Size"

Dim X_Galvanized As String

X_Galvanized = "Galvanized"

Dim X_Date_Completed As String

X_Date_Completed = "Completion Date"



Dim oProp_Array As New ArrayList

oProp_Array.Add(X_PaintCode)

oProp_Array.Add(X_Size)

oProp_Array.Add(X_Galvanized)

oProp_Array.Add(X_Date_Completed)



'define custom prp[erty collection

oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")



For Each X_oProp_Array In oProp_Array

	Try

	'set property value

	oProp = oCustomPropertySet.Item(X_oProp_Array)

	Catch

	MessageBox.Show("Prop exists: No", "Title")

	' Assume error means not found so create it

	oCustomPropertySet.Add("", X_oProp_Array)

	End Try

	oYN = MessageBox.Show("Do you need to assign TYPE for " & X_oProp_Array & "?", "Title", MessageBoxButtons.YesNo)

	If oYN = vbYes Then oType_Assign(oRuleNo, X_oProp_Array)

Next X_oProp_Array



iLogicVb.UpdateWhenDone = True

End Sub



Sub oType_Assign(oRuleNo, X_oProp_Array)

oSubName = "ASSIGN TYPE"

Dim oProp_String As String 

oType_String = "String"

Dim oProp_Dbl As Double

oType_Dbl = "Double"

Dim oProp_Bool As Boolean

oType_Bool = "Boolean"

Dim oProp_Date As Date

oType_Date = "Date: mm/dd/yyyy"

'

Dim oTypes_Array As New ArrayList

oTypes_Array.Add(oType_String)

oTypes_Array.Add(oType_Dbl)

oTypes_Array.Add(oType_Bool)

oTypes_Array.Add(oType_Date)

oTypes_Selected = InputListBox("SELECT TYPE:", oTypes_Array, oTypes_Array(0), oRuleNo, X_oProp_Array)

Dim oTime As DateTime 

Select Case oTypes_Selected

Case oType_String

	X_oProp_Data = InputBox("Enter data for " & X_oProp_Array & ": ", oRuleNo, "STRING DATA ONLY") 'no default value
 	iProperties.Value("Custom", X_oProp_Array) = X_oProp_Data
Case oType_Dbl

	X_oProp_Data = InputBox("Enter data for " & X_oProp_Array & ": ", oRuleNo, "NUMERICAL DATA ONLY") 'no default value
	Dim numeric As Double 
	numeric = Convert.ToDouble(X_oProp_Data)
	iProperties.Value("Custom", X_oProp_Array) = numeric
Case oType_Bool

	X_oProp_Data = InputBox("Enter data for " & X_oProp_Array & ": ", oRuleNo, "Boolean only") 'no default value
	Dim bool As Boolean 
	bool = Boolean.Parse(X_oProp_Data)
	iProperties.Value("Custom", X_oProp_Array) = bool
Case oType_Date

	X_oProp_Data = InputBox("Enter data for " & X_oProp_Array & ": ", oRuleNo, Now.ToString("MM/dd/yyyy")) 'no default value
	 
	oTime = DateTime.Parse(X_oProp_Data)
	iProperties.Value("Custom", X_oProp_Array) = oTime 
End Select

'

''set custom property values



End Sub  

iProperties.PNG

Thanks and regards,

 

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 4 of 24

RoyWickrama_RWEI
Advisor
Advisor

Thanks a for for the reply.

I will study the whole rule and revert to you later.

0 Likes
Message 5 of 24

RoyWickrama_RWEI
Advisor
Advisor

Thanks for the question. Basically, currently, I need to view  (with a message box prompt) the type of the iProperty. However, I may explore all the options able to do. I will get back to you again.

0 Likes
Message 6 of 24

RoyWickrama_RWEI
Advisor
Advisor

Again, thanks for the fix. It is fine. With the help, I was able to add some try .. catch ... end try to avoid rule crashing.

I also need to extract type with a line of rule like below: 

MessageBox.Show("TYPE: " & iProperties.Type("Custom", X_oProp_Array), "Title")

 But, error comes:

... Type' is not a member of 'Autodesk.iLogic.Interfaces.IiProperties'

Could you suggest a fix. Thanks.

0 Likes
Message 7 of 24

chandra.shekar.g
Autodesk Support
Autodesk Support

@RoyWickrama_RWEI,

 

Are you looking for value type of property or type of iProperty?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 8 of 24

RoyWickrama_RWEI
Advisor
Advisor

Thanks for responding.

Yes. I nee d to do with the following:

Dim oTypes_Array As New ArrayList
'oTypes_Array.Add(iProperties.Type("Custom", X_oProp_Array))
oTypes_Array.Add(oType_String)
oTypes_Array.Add(oType_Dbl)
oTypes_Array.Add(oType_Bool)
oTypes_Array.Add(oType_Date)
oTypes_Selected = InputListBox("SELECT TYPE:", oTypes_Array, oTypes_Array(0), oRuleNo, X_oProp_Array)

The first line commented because it does not go through.

Please reply.

0 Likes
Message 9 of 24

RoyWickrama_RWEI
Advisor
Advisor

@chandra.shekar.g wrote:

@RoyWickrama_RWEI,

 

Are you looking for value type of property or type of iProperty?

 

Thanks and regards,



Yes. My previous reply was not clear, I guess.

0 Likes
Message 10 of 24

RoyWickrama_RWEI
Advisor
Advisor

I explored a little bit more again. I think, this is not possible.  

oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
MessageBox.Show("Message, Before: " & X_oProp_Array, "Title")
oXX = oCustomPropertySet.Item(X_oProp_Array)
MessageBox.Show("Message" _
& vbLf & "Name: " & oXX.Name _
& vbLf & "Value: " & oXX.Value _
& vbLf & "Type: " & oXX.Type, "Title")

Type is retrievable, but useless because it is the same for all types (0339072 for all Text, Date, Number, Yes or No).

Several years ago, I had more problems like this, then I gave up. Coming back (I need to learn), I see Autodesk Inventor still has areas to develop. 

Bool.PNGDate.PNGString.PNGNumber.PNG

 

Size.PNG

Just information. Please let me know if you have some information.

Thanks.

Message 11 of 24

RoyWickrama_RWEI
Advisor
Advisor

You have helped me a lot, and I thought not to disturb you: this is my headache.

I am getting around it, will let you know soon.

Thanks for your help.

0 Likes
Message 12 of 24

RoyWickrama_RWEI
Advisor
Advisor
Accepted solution

I accepted your code as a solution as it led me to get around my current need.

Attached hereto is the code I developed with your help.

 

Let me know if you have any comments (if you don't bother spending time). Thanks a lot.

 

0 Likes
Message 13 of 24

RoyWickrama_RWEI
Advisor
Advisor

Replacing the data roe in the array:

Dim oTypes_Array As New ArrayList
oTypes_Array.Add(oType_String)
oTypes_Array.Add(oType_Int)
oTypes_Array.Add(oType_Dbl)
oTypes_Array.Add(oType_Bool)
oTypes_Array.Add(oType_Date)

For Each oItem In oTypes_Array
	If oItem = oXX_Type Then
	oType_Edit = oXX_Type
	End If
Next oItem

oTypes_Selected = InputListBox("SELECT TYPE:", oTypes_Array, oType_Edit, oRuleNo, oProp_Array_Selected)

 

0 Likes
Message 14 of 24

chandra.shekar.g
Autodesk Support
Autodesk Support

@RoyWickrama_RWEI,

 

Try below iLogic code to get data type of custom property.

 

Sub Main()
	Dim doc = ThisDoc.Document

	Dim oProperty As Inventor.Property 
	oProperty = doc.PropertySets.Item("Inventor User Defined Properties").Item("oText")

	Dim oValue As String 
	oValue = oProperty.Value 
	
	Try 
		Dim oTime As DateTime 
		oTime = DateTime.Parse(oValue)
		MessageBox.Show("Value is Date Type", "Property type")
		Exit Sub		 
	Catch 
		 GoTo Numeric
	End Try
	
	
	Numeric:
	Try
		Dim oNumber As Integer 
		oNumber = Convert.ToInt16(oValue)
		MessageBox.Show("Value is Number Type", "Property type")
		Exit Sub
	Catch 
		  GoTo StringValue 
	End Try 

	StringValue : 
	If oValue = "True" Or oValue = "False" Then
		MessageBox.Show("Value is Boolean Type", "Property type")
	Else
		MessageBox.Show("Value is Text Type", "Property type")
	End If  
	
End Sub 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 15 of 24

ReneRepina
Collaborator
Collaborator

Hello,

one question about this topic.

We use custom iproperty for identification. It is a string parameter (because it can be just a 6-digit number or containing other symbols and letters).

Sometimes problem occurs that it writes 6-digit number as NUMBER, except as string. It there any possible way to check that with iLogic? Problem is that if I use above code, value of 123456, can be either a number or string, so if I try to parse or convert, this always go through, so I cannot distinguish between integer and string.

One way can be to store the value and enter it as "123456", but that dirties the document and we do not wanna do that if it is not needed. So in this situation, I would compare types, if it is a number, rewrite is as string. Is this possible?

0 Likes
Message 16 of 24

NachoShaw
Advisor
Advisor

Hey

 

I put this together for when i am working with Properties to make sure i get the correct type. I use it VB.Net but im sure you could get it to work in iLogic

 

Friend Function GetPropertyType(ByRef PropVal As String) As Object

Dim dbl As Double
If Double.TryParse(PropVal, NumberStyles.Float, CultureInfo.InvariantCulture, dbl) Then Return dbl

Dim bln As Boolean
If Boolean.TryParse(PropVal, bln) Then Return bln

Dim dte As Date
If Date.TryParse(PropVal, dte) Then Return dte

Dim int As Integer
If Integer.TryParse(PropVal, int) Then Return int

Return PropVal
End Function

 

to use in a function

Dim PropertyType As Object = GetPropertyType(PropertyValue)

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 17 of 24

ReneRepina
Collaborator
Collaborator

@NachoShaw 

Thanks for the reply. Unfortunately this won't work in my case, because if you have a string "123456" and try parse it to "Double" or "Int" it will return true, so you cannot distinguish the data type inside iProps (at least I do not know the command).

 

In my situation, I have a value of "123456" (it can be a text or a number) and I need to distinguish between those two types, because I need explicitly as text type. So basically check if it is a string leave it like it is and if it is a number, convert it to string.

0 Likes
Message 18 of 24

NachoShaw
Advisor
Advisor

Ok. So if you need the number as string regardless, why not convert it

 

Dim dVal as Double = 123456

Dim scale as String = "123456"

Try

   Convert.ToString(dVal)

   Convert.ToString(sVal)

Catch ex As Exception

 

End Try

 

   

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 19 of 24

ReneRepina
Collaborator
Collaborator

@NachoShaw 

I need this for iProps. If I use "Convert.ToString(value)", data type in iProps still stays as it is. For example, if I have a 123456 as number, convert it to string and write the value to iProp, it will still be as a number.

But, this works though:

iProperties.Value("Custom", "test") = Convert.ToString(iProperties.Value("Custom", "test"))

 

One of the problems I am having currently is that I do not want to "dirty" the file, if iProp is already as text. I would need a boolean to compare data types. If data is a "number" data type, covert it (as you suggested) OR delete and write parameter again in text and if it is already a text, do not do anything, therefor skipping convert (and not dirty the file).

0 Likes
Message 20 of 24

NachoShaw
Advisor
Advisor

Hey

 

it shouldnt be still a number though. if you are adding as a number 123456, it will be a number but if you add as a string "123456" it will be a string.

 

I did a bunch of iProperty work recently and the function i made to determine the Type was needed because all of my values were originally added as text, even long numbers. I needed the Type check to add in the type and then added the value as that iProperty value as a Type like this:

 

Dim customPropSet As Inventor.PropertySet = Doc.PropertySets.Item("Inventor User Defined Properties")
Dim ValueIn As Object = GetPropertyType(PropertyValue)
Try
   Dim prop As Inventor.Property = customPropSet.Add(ValueIn, PropertyName)
Catch ex As ArgumentException
   Dim prop As Inventor.Property = customPropSet.Item(PropertyName)
   prop.Value = ValueIn
End Try

 

i was setting the ValueIn as the as the value and the type by using the GetPropertyType() function and then when passing into the iProperties, it was setting the value as they Type.

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes