Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ilogic create custom ipropertie

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
freece-cl
17888 Views, 16 Replies

ilogic create custom ipropertie

Hello

 

I would like to create an new custom ipropertie with ilogic.

The reason is the contentcenter, thei haven't custom iproperties.

 

How should the code work:

if

propertie "test" is available

write the value in the propertie

else if

propertie test isn't available

create prpertie

write the value in the propertie

end if

 

How can i check if the propertie is already exists in the file?

How can i create a new custom iPropertie?

How solves other this problem?

 

The rest of teh code is ready and works fine.

 

i've faund already some code with VBA but not with "pure" ilogic.

 

Thanks and Greetings Daniel

 

 

 

 

16 REPLIES 16
Message 2 of 17
MjDeck
in reply to: freece-cl

Where are you going to put the iLogic rule to create the custom iProperty?  Will you put it in the Content Center part or in the assembly?  If it's in the assembly, how will it find the Content Center part and when will the rule run?

 

Here's some code to create a custom iProperty in a part, if it is not found:

 

Dim propertyName As String = "MyProperty"
Dim propertyValue as String = "Test Value"

customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
Try
      prop = customPropertySet.Item(propertyName)
Catch
      ' Assume error means not found
      customPropertySet.Add("", propertyName)
End Try

iProperties.Value("Custom", propertyName) = propertyValue

 

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 17
freece-cl
in reply to: freece-cl

Hello Mike

 

Thanks for your answer.

 

I'd like to have an external rule.The user can start it,  and fill in the values of the properties.

The templates have already the custom iproperties, but the contencenterfiles (profile) not.

So I need the rule to check if the propertie is there, if not so I have to create it, and fill in the value.

 

I will check your code in the next days.

 

Thank you, for your fast answer.

Daniel

Message 4 of 17
freece-cl
in reply to: MjDeck

Hello Mike

 

I've checked your code and it works fine. Thank you.

I' ve use it as a external rule, wich the user can start manually.

 

The missing iProperties can now add easily.

 

Greetings Daniel 

Message 5 of 17

Heres an updated version using a loop to populate multiple custom iproperties.  it also gives you an opportunity to fill in the property if its "null".

 

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

Dim iprop(5) As String
iprop(1) = "Part Number"
iprop(2) = "Cage Code"
iprop(3) = "Material"
iprop(4) = "Material Specification"
iprop(5) = "MSSv(part) Description"

For k = 1 To 5
Dim prop(k) As String
Try
prop(k) = iProperties.Value("Custom", iprop(k))
Catch
'Assume error means not found
customPropertySet.Add("", iprop(k))
iProperties.Value("Custom", iprop(k)) = "null"
End Try
Next

For j = 1 To 5
Dim var(j) As String
If iProperties.Value("Custom", iprop(j)) = "null" Then
var(j) = InputBox("A value is needed for iProperty: " & iprop(j), "Warning", "")
iProperties.Value("Custom", iprop(j)) = var(j)
End If
Next
Thomas Fitzgerald

Principal Implementation Consultant
Message 6 of 17
cadman777
in reply to: MjDeck

Mike,

 

Thanx for this piece of code. It solved my problem. I tried writing it myself (a total nubie at iLogc), but after 4 hours of stupidity, I gave up and looked for it on the web.

 

This reminds me of my AutoLISP days where you really had to know DIESEL and VB to make it work the way you want. That's not an option for non-programmers like me.

 

I sure wish there was a way someone could explain what the symantics, syntax and grammer of this piece of code means, like the LISP books I used in the bygone era.

 

Anyways, thanx for this piece of code.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 7 of 17
n.benda
in reply to: thomas.fitzgerald

Hey Thomas,

 

This was where i was looking for.

Thank you.

 

2 Points;

- Is it possible to make the multiple propertys in a "form" style.

- When i'm using the rule in a assy, it only runs 1 time. What do i need to change that i can use anytime i want. To change the valvue of the propertys.

 

Thx again.

 

Nick

Message 8 of 17

Is it possible to cycle through all parts in my assembly instead?

Message 9 of 17
dusan.naus.trz
in reply to: MjDeck

Hi, thank you for your comment. I'll give an additional comment for the type setting. Sample video in attachment.

Dim propertyName As String  = "HrubaHmotnost"
Dim propertyValue As Double = 3.14159

' Set values for the Type.
'Dim propertyValue As String = "Some sample text."
'Dim propertyValue As Double = 3.14159
'Dim propertyValue As Date = Now
'Dim propertyValue As Boolean = True

customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
Try
      prop = customPropertySet.Item(propertyName)
Catch
      ' Assume error means not found
      customPropertySet.Add("", propertyName)
End Try

iProperties.Value("Custom", propertyName) = propertyValue

 

Message 10 of 17

I also used this topic. I attach for others, maybe it will help too. Context.

https://forums.autodesk.com/t5/inventor-customization/ilogic-check-the-type-of-custom-iproperties/td...

Message 11 of 17
WCrihfield
in reply to: MjDeck

Here's something along the same lines too.  It's a bit lengthy, but good information.

https://knowledge.autodesk.com/search-result/caas/simplecontent/content/list-all-iproperties-and-how... 

Wesley Crihfield

EESignature

Tags (1)
Message 12 of 17
cadman777
in reply to: dusan.naus.trz

Great stuff, thanx!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 13 of 17
jpi656UL
in reply to: dusan.naus.trz

 
 
 

 

I found your solution very helpful when it comes to creating new custom iproperties using ilogic, but then I wondered if it is possible to create an iproperty dependent on the current sheet that is active? For example I would like to create parameter having the suffix of the active sheet number (while having active sheet no. 4 I want to create iproperty name "an_example_4"). I don't know if there is any way to do that. I thought it would look somewhat like that:

 

Dim oSheet As Sheet
Dim SheetNumber as String
Dim propertyName As String = "example_" & Sheet.Number

Also later on dependent on the active sheet I would like to set this parameter value to first prompted entry, so when I am in sheet 6 and I place the titleblock using rule it places empty value if the parameter "an_example_6" hadn't been defined before or if it was then it places the value as I think it would look like below.

 

ActiveSheet.SetTitleBlock("Titleblock_name",an_example_4)

I would appreciate any help in solving this toughie

 

 

Message 14 of 17
WCrihfield
in reply to: jpi656UL

Hi @jpi656UL.  If it is possible to set-up that way, it would have to include some 'triggers' that would automatically run the rule again every time the active sheet changes, to keep the property's value up to date.  Currently there is only one event listed in the 'Event Triggers' dialog which has anything to do with drawings specifically, and that is 'Drawing View Change' (uses the OnViewUpdate event), which only gets triggered when something in the model changed, causing the view to be updated to match the model.  So that trigger won't work for this situation.  You would need to create a custom event handler code to be able to trigger this rule to run every time the active sheet changes.  The only other drawing specific event I can think of that has an event handler code established for it is the 'OnRetrieveDimensions', which is obviously not what we want here.  So, I'm not sure any code exists to handle the event we want to monitor here.

 

But here would be one possible representation of the iLogic rule for creating/updating a custom iProperty that records the name (or number) of the active sheet.  Then some code to place the title block with that value in its first prompted entry value.

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = oDDoc.ActiveSheet
Dim oCProps As PropertySet = oDDoc.PropertySets.Item(4)
Dim oNameProp, oNumProp As Inventor.Property
Try
	oNameProp = oCProps.Item("ActiveSheetName")
	oNameProp.Value = oSheet.Name
Catch
	oNameProp = oCProps.Add(oSheet.Name, "ActiveSheetName")
End Try
'Try
'	oNumProp = oCProps.Item("ActiveSheetNumber")
'Catch
'	oNumProp = oCProps.Add(0, "ActiveSheetNumber")
'End Try
'For i As Integer = 1 To oDDoc.Sheets.Count
'	If oDDoc.Sheets.Item(i) Is oSheet Then
'		oNumProp.Value = i
'	End If
'Next
Dim oTBDef As TitleBlockDefinition = oDDoc.TitleBlockDefinitions.Item("TitleBlockDefName")
Dim oPromptStrings() As String = {oNameProp.Value}
oSheet.AddTitleBlock(oTBDef, TitleBlockLocationEnum.kBottomRightPosition, oPromptStrings)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb:or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

Message 15 of 17
jpi656UL
in reply to: WCrihfield

Hi @WCrihfield,

 

This works really good, thank you for your time and readiness to help. Though what I really meant the rule would do is to create each time a new parameter dependent on what sheet I have active currently, not override the same parameter each time - for example if I ran the rule for sheet 1 & 4 I would have 2 parameters created, following your denotation "ActiveSheetName1" and "ActiveSheetName4" , so the more sheets I create the more custom properties I could get let's say assigned to particular sheet.

But let me just get immersed into the problem I have, maybe I am overcomplicating things, maybe there is easier way to get the same effect I need - if I don't find any I would contact you again if you don't mind, but then I will clearly describe why I need these parameters to be created, what exactly I want to achieve by having them, maybe this way it will be more clear, as for now I don't want you to needlessly waste your time.

 

Once again I appreciate your help

Message 16 of 17

Hey mate,

this works fine. Only one doubt. How do I save it as number. I meant custom property type - number and not text. 

Message 17 of 17

Hi @planner_mobbs_engineering.  Quite simply, the value data Type of a custom iProperty is set by the Type of data you set at its value.  Because of this, you can actually change a custom iProperty's value type by simply setting a different type of value to it.  For instance, any value you give to it that is within quotation marks will be understood as text (String), and therefore will set its data type to text.  If you set an unquoted numerical value to it, which has decimal places, it will be understood as number (Double) by default.  If you set an unquoted numerical value to it, which has no decimal places, it will be understood as number (Integer).  If it is formatted as a Date, it will be recognized as Date.  If you set either True or False as its value, it will be recognized as 'Yes or No' (Boolean).

However, standard (not custom), pre-existing iProperties can NOT have their value data type changed this way.  And many of the standard ones are also ReadOnly, instead of Read/Write.

Wesley Crihfield

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report