I-Logic for Custom properties

I-Logic for Custom properties

didin.suryadi6JREK
Advocate Advocate
1,780 Views
13 Replies
Message 1 of 14

I-Logic for Custom properties

didin.suryadi6JREK
Advocate
Advocate

Hello

 

Can anyone check below i-logic code?

=============================

Dim propertyName1 As String = "Rev Desc"
Dim propertyValue1 As String = ""

customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
Try
      prop = customPropertySet.Item(propertyName1)
Catch
      customPropertySet.Add("", propertyName1)
  End Try
  
	Dim propertyName2 As String = "Rev Date"
Dim propertyValue2 As String = "mm/dd/yyyy"

customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
Try
      prop = customPropertySet.Item(propertyName2)
Catch
      customPropertySet.Add("mm/dd/yyyy", propertyName2)   
	  
  End Try

	Dim propertyName3 As String = "Salvagnini Proficient"
Dim propertyValue3 As String = "Yes"

customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
Try
      prop = customPropertySet.Item(propertyName3)
Catch
      customPropertySet.Add("Yes/No", propertyName3)  
	  
  End Try
====================================================
The problem on the result i have is the "Rev Date" shown as text meanwhile the purpose i need is "Date"
and the 2nd one on string "Salvagnini proficient" it's needs to be a multpile choices 'YES'NO"

Please see attached the wrong result and what i need.Custome Properties (wrong).JPG

Thanks


 

0 Likes
Accepted solutions (1)
1,781 Views
13 Replies
Replies (13)
Message 2 of 14

JhoelForshav
Mentor
Mentor

Hi @didin.suryadi6JREK 

You must use a value of the datatype expected by the property type you want it to be.

For example, if you want a date property, the value must be of a date type.

 

Dim propertyName1 As String = "Rev Desc"
Dim propertyValue1 As String = ""

Dim customPropertySet As PropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")


Try
	prop = customPropertySet.Item(propertyName1)
Catch
	customPropertySet.Add("", propertyName1)
End Try

Dim propertyName2 As String = "Rev Date"
Dim propertyValue2 As Date = Today.Date


Try
	prop = customPropertySet.Item(propertyName2)
Catch
	customPropertySet.Add(propertyValue2, propertyName2)
End Try

Dim propertyName3 As String = "Salvagnini Proficient"
Dim propertyValue3 As Boolean = True


Try
	prop = customPropertySet.Item(propertyName3)
Catch
	customPropertySet.Add(propertyValue3, propertyName3)

End Try
Message 3 of 14

Anonymous
Not applicable

Pulled directly from the API help file.

 

Public Sub CreateCustomProperties()
    ' Get the active document.
    Dim invDoc As Document
    Set invDoc = ThisApplication.ActiveDocument
    
    ' Get the user defined (custom) property set.
    Dim invCustomPropertySet As PropertySet
    Set invCustomPropertySet = invDoc.PropertySets.Item("Inventor User Defined Properties")
    
    ' Declare some variables that will contain the various values.
    Dim strText As String
    Dim dblValue As Double
    Dim dtDate As Date
    Dim blYesOrNo As Boolean
    
    ' Set values for the variables.
    strText = "Some sample text."
    dblValue = 3.14159
    dtDate = Now
    blYesOrNo = True
    
    ' Create the properties.
    Dim invProperty As Property
    Set invProperty = invCustomPropertySet.Add(strText, "Test Test")
    Set invProperty = invCustomPropertySet.Add(dblValue, "Test Value")
    Set invProperty = invCustomPropertySet.Add(dtDate, "Test Date")
    Set invProperty = invCustomPropertySet.Add(blYesOrNo, "Test Yes or No")
End Sub

 

For a yes/no custom iProperty you will need to provide a variable with a boolean type.

 

Best of luck! 

0 Likes
Message 4 of 14

didin.suryadi6JREK
Advocate
Advocate

HI,

 

I tried but came up msg error, why is that?

 

errors.JPG

0 Likes
Message 5 of 14

didin.suryadi6JREK
Advocate
Advocate

hi

 

Thanks, but the same error msg came up

 

error2.JPG

0 Likes
Message 6 of 14

didin.suryadi6JREK
Advocate
Advocate

HI, THIS IS WHAT AM TALKING ABOUT, THANKS

 

IT's WORKED.

 

worked solution.JPG

0 Likes
Message 7 of 14

robertast
Collaborator
Collaborator

 @Anonymous      You have provided an example that runs VBA makro and you are trying to write it to iLogic. As a result, you get an error. Replace "Public Sub CreateCustomProperties ()" with "Sub main ()". And everywhere there is the word “Set”. Erase them.

And just read all @JhoelForshav  posts in this forum and you will find a lot of interesting and useful 👍

Message 8 of 14

didin.suryadi6JREK
Advocate
Advocate

Hi 

 

Just come up with another question, what string do i have to put on "Rev Date" if i want it to leave empty on the first entry value, so it will be filled when we do the revision.

 

Dim propertyName2 As String = "Rev Date"
Dim propertyValue2 As Date = Today.Date


  Attached the final result that i wanted.

 

Appreciated your help.Empty value on Date string.JPG

0 Likes
Message 9 of 14

didin.suryadi6JREK
Advocate
Advocate

Hi

 

Thanks for your correction, would you please take a look to my latest reply? on "Rev Date" i want it to leave empty on the first entry value, so it will be filled when we do the revision.

 

I have attached on replied with the pic that i wanted.

 

Appreciated your prompt reply.

0 Likes
Message 10 of 14

robertast
Collaborator
Collaborator

Do you use code written by  @JhoelForshav  ?
He will stop sleeping and write you an answer. If you're having trouble waiting, 🙂

try changing

"Dim propertyValue2 As Date = Today.Date"

to      Dim DimValue2 As Date = " "

Message 11 of 14

didin.suryadi6JREK
Advocate
Advocate

Hi Rob

 

sorry for hurry, he is sleeping and will read by tomorrow, so do i.

Anyway i tried with your suggestion and it looks like the string did not match,

See Attached

 

Thank You very muchError String.JPG

0 Likes
Message 12 of 14

robertast
Collaborator
Collaborator

Forgive me  @JhoelForshav  because I was a bad student, giving the wrong advice. 🙁

Message 13 of 14

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @didin.suryadi6JREK 

The only way I can get this to work is to create the property with a date, then make it Null. Like this 🙂

Dim propertyName1 As String = "Rev Desc"
Dim propertyValue1 As String = ""

Dim customPropertySet As PropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")


Try
	prop = customPropertySet.Item(propertyName1)
Catch
	customPropertySet.Add("", propertyName1)
End Try

Dim propertyName2 As String = "Rev Date"
Dim propertyValue2 As Nullable(Of Date) = Date.Now
Dim NullDate As Nullable(Of Date)
Try
	prop = customPropertySet.Item(propertyName2)
Catch
	customPropertySet.Add(propertyValue2, propertyName2)
	iProperties.Value("Custom", propertyName2) = NullDate
End Try

Dim propertyName3 As String = "Salvagnini Proficient"
Dim propertyValue3 As Boolean = True


Try
	prop = customPropertySet.Item(propertyName3)
Catch
	customPropertySet.Add(propertyValue3, propertyName3)

End Try
Message 14 of 14

didin.suryadi6JREK
Advocate
Advocate

Waw,,.. Its working now, 

Thank You very much sir, have a good day

 

God bless youfinally works.JPG