iLogic rule to get a propmted text value and populate iProperties

iLogic rule to get a propmted text value and populate iProperties

jfildes
Enthusiast Enthusiast
4,399 Views
17 Replies
Message 1 of 18

iLogic rule to get a propmted text value and populate iProperties

jfildes
Enthusiast
Enthusiast

Hello,

 

I'm looking to create an iLogic rule that would read an existing prompted entry in my title block and populate a custom iProperty.

 

the prompted entry is called <MATERIALS> and the custom iProperty is called "Materials". 

 

I've done some digging and I found this but I couldn't quite get it to work for me.

 

Ultimately I envision the code to work as outlined below and could just use a little help to get over the hurdle.

'Read Title Block from Active Sheet
 
    Dim oDoc  As Document
    oDoc = ThisApplication.ActiveDocument
    Dim oSheet  As Sheet
    oSheet = oDoc.ActiveSheet
    Dim oTB1  As TitleBlock
    oTB1 = oSheet.TitleBlock
    Dim oPrompt As String
    
    ' Find the Prompted Entry called <MATERIALS> in the Title Block
    ' Code
        
    'get the result string of the prompt text
    'Code

     'Set the value of the Prompted Entry to the Custom iProperties
     iProperties.Value("Custom","Materials") = oPrompt

I'm still a little new to all of this but I have appreciated the help I've received from this community before and know that you guys will help me find an answer. Thanks!

 

 

0 Likes
Accepted solutions (1)
4,400 Views
17 Replies
Replies (17)
Message 2 of 18

Curtis_Waguespack
Consultant
Consultant

Hi jfildes,

 

I think this will work for you.

 

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

 

 

 

'Read Title Block from Active Sheet
 
Dim oDoc  As Document
oDoc = ThisApplication.ActiveDocument
Dim oSheet  As Sheet
oSheet = oDoc.ActiveSheet
Dim oTB1  As TitleBlock
oTB1 = oSheet.TitleBlock
Dim titleDef As TitleBlockDefinition
titleDef = oTB1.Definition
Dim oPrompt As TextBox

' Find the Prompted Entry called <MATERIALS> in the Title Block
For Each defText As TextBox In titleDef.Sketch.TextBoxes
    If defText.Text = "<MATERIALS>" Then
		oPrompt = defText						
         Exit For			  
    End If
Next	

'write iprop to prompted entry
oTB1.SetPromptResultText(oPrompt, iProperties.Value("Custom","Materials"))
    

 

 

EESignature

Message 3 of 18

jfildes
Enthusiast
Enthusiast

Curtis,

I tried out the code and it seems like it's actually doing the opposite of what I was looking for. It is trying to populate the prompted text with the value in the iProperty. The code works successfully for that, however I'm looking to populate the iProperty from the existing prompted entry.

 

Would I just have to switch the values around? Something like this?

iProperties,Value("Custom","Materials") = oPrompt

I tried something like that but I end up with an error. Seems like a step in the right direction, just need to switch around the read/write values. 

0 Likes
Message 4 of 18

jfildes
Enthusiast
Enthusiast
Accepted solution

SyntaxEditor Code Snippet

'Read Title Block from Active Sheet
 
Dim oDoc  As Document
oDoc = ThisApplication.ActiveDocument
Dim oSheet  As Sheet
oSheet = oDoc.ActiveSheet
Dim oTB1  As TitleBlock
oTB1 = oSheet.TitleBlock
Dim titleDef As TitleBlockDefinition
titleDef = oTB1.Definition
Dim oPrompt As TextBox

' Find the Prompted Entry called <MATERIALS> in the Title Block
For Each defText As TextBox In titleDef.Sketch.TextBoxes
    If defText.Text = "<MATERIALS>" Then
        oPrompt = defText                        
         Exit For              
    End If
Next    


'write prompted entry to iprop

Dim Mat As String
Mat=oTB1.GetResultText(oPrompt)
iProperties.Value("Custom","Materials")=Mat
Message 5 of 18

jfildes
Enthusiast
Enthusiast
Thanks again for the help. It was greatly appreciated
0 Likes
Message 6 of 18

Curtis_Waguespack
Consultant
Consultant

@jfildes wrote:

....I tried out the code and it seems like it's actually doing the opposite of what I was looking for.


Hi jfildes,

 

Smiley Embarassed ooops!

 

It looks like you got it sorted out, though. Thanks for posting back the solution, I'm sure someone will find it helpful in the future.

 

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

 

 

EESignature

Message 7 of 18

m.verbunt
Advocate
Advocate

This is great! Is there a way to make this work for multiple promted entries in the same titleblock? I would like to get five fields retreived from the titleblock.

These would be:

-Description

-Description2

-Partnumber

-Date

-Tolerance

 

Can anyone give me a push in the right direction? It would be greatly apperciated.

 

 

0 Likes
Message 8 of 18

jfildes
Enthusiast
Enthusiast

@m.verbunt wrote:

This is great! Is there a way to make this work for multiple promted entries in the same titleblock? I would like to get five fields retreived from the titleblock.

These would be:

-Description

-Description2

-Partnumber

-Date

-Tolerance

 

Can anyone give me a push in the right direction? It would be greatly apperciated.

 

 



I believe you could easily adapt this into pulling multiple prompted text fields, you just need to write them to appropriate variables.

 

In the "For Each" block of code, the code is pouring through each of the text boxes in the title block. the "If" statement is giving it the criteria to look for and setting it to oPrompt. You could expand this with multiple statements that are checking your criteria. So something like:

' Find the Prompted Entry called <MATERIALS> in the Title Block
For Each defText As TextBox In titleDef.Sketch.TextBoxes
    If defText.Text = "<MATERIALS>" Then
		oPrompt = defText
	ElseIf defText.Text = "<Description>" Then
		oPrompt2 = defText
	ElseIf defText.Text = [insert your criteria here ] Then
		oPrompt[some unique identifier] = defText
        ' Exit For <- You need to remove this line as it is exiting the loop once it finds the variable you are looking for
	'Else Return
    End If
Next	

Then in the "Write prompted entry" section, just match up your unique identifiers to your iProperties:

'write prompted entry to iprop

Dim Mat As String
Dim Desc As String
Dim Whatever As String

Mat=oTB1.GetResultText(oPrompt)
iProperties.Value("Custom","Materials")=Mat

Desc = oTB1.GetResultText(oPrompt2)
iProperties.Value("Project", "Description") = Desc

Whatever = oTB1.GetResultText(oPrompt [your unique identifier ])
iProperties.Value([Section Of the iProperties],[specific iProperty])=Whatever

I think that should get you headed in the right direction. Hopefully it helps you out!

Message 9 of 18

m.verbunt
Advocate
Advocate

@jfildes wrote:

@m.verbunt wrote:

This is great! Is there a way to make this work for multiple promted entries in the same titleblock? I would like to get five fields retreived from the titleblock.

These would be:

-Description

-Description2

-Partnumber

-Date

-Tolerance

 

Can anyone give me a push in the right direction? It would be greatly apperciated.

 

 



I believe you could easily adapt this into pulling multiple prompted text fields, you just need to write them to appropriate variables.

 

In the "For Each" block of code, the code is pouring through each of the text boxes in the title block. the "If" statement is giving it the criteria to look for and setting it to oPrompt. You could expand this with multiple statements that are checking your criteria. So something like:

' Find the Prompted Entry called <MATERIALS> in the Title Block
For Each defText As TextBox In titleDef.Sketch.TextBoxes
    If defText.Text = "<MATERIALS>" Then
		oPrompt = defText
	ElseIf defText.Text = "<Description>" Then
		oPrompt2 = defText
	ElseIf defText.Text = [insert your criteria here ] Then
		oPrompt[some unique identifier] = defText
        ' Exit For <- You need to remove this line as it is exiting the loop once it finds the variable you are looking for
	'Else Return
    End If
Next	

Then in the "Write prompted entry" section, just match up your unique identifiers to your iProperties:

'write prompted entry to iprop

Dim Mat As String
Dim Desc As String
Dim Whatever As String

Mat=oTB1.GetResultText(oPrompt)
iProperties.Value("Custom","Materials")=Mat

Desc = oTB1.GetResultText(oPrompt2)
iProperties.Value("Project", "Description") = Desc

Whatever = oTB1.GetResultText(oPrompt [your unique identifier ])
iProperties.Value([Section Of the iProperties],[specific iProperty])=Whatever

I think that should get you headed in the right direction. Hopefully it helps you out!


Thank you so much. I will have a go at this, and adapt it to my needs. I'll let you know when I got it working. Once again a big thank you for pushing me in the right direction!

0 Likes
Message 10 of 18

m.verbunt
Advocate
Advocate
'Read Title Block from Active Sheet
 
Dim oDoc  As Document
oDoc = ThisApplication.ActiveDocument
Dim oSheet  As Sheet
oSheet = oDoc.ActiveSheet
Dim oTB1  As TitleBlock
oTB1 = oSheet.TitleBlock
Dim titleDef As TitleBlockDefinition
titleDef = oTB1.Definition
Dim oPrompt As TextBox

' Find the Prompted Entry called <MATERIALS> in the Title Block
For Each defText As TextBox In titleDef.Sketch.TextBoxes
    If defText.Text = "<MATERIALS>" Then
		oPrompt = defText

	ElseIf defText.Text = "<Bemaning 1>" Then
		oPrompt2 = defText
		
	ElseIf defText.Text = "<BENAMING 1>" Then
		oPrompt3 = defText
		
	ElseIf defText.Text = "<BENAMING 2>" Then
		oPrompt4 = defText
		
	ElseIf defText.Text = "<Eenheden>" Then
		oPrompt5 = defText
		
	ElseIf defText.Text = "<DATUM>" Then
		oPrompt6 = defText
		
	ElseIf defText.Text = "<Tolerantie>" Then
		oPrompt7 = defText		
		
	ElseIf defText.Text = "<MATERIAL>" Then
		oPrompt8 = defText
		
	ElseIf defText.Text = "<Klant>" Then
		oPrompt9 = defText
		
	ElseIf defText.Text = "<Referentie>" Then
		oPrompt10 = defText

        ' Exit For <- You need to remove this line as it is exiting the loop once it finds the variable you are looking for
	'Else Return
    End If
Next	

'write prompted entry to iprop

Dim Mat As String
Dim Mat2 As String
Dim Desc1 As String
Dim Desc1a As String
Dim Desc2 As String
Dim Units As String
Dim oDatum As String
Dim Tol As String
Dim klant As String
Dim oReference As String

Mat = oTB1.GetResultText(oPrompt)
iProperties.Value("Custom", "TMP_MATERIALS") = Mat

Desc1 = oTB1.GetResultText(oPrompt2)
iProperties.Value("Custom", "TMP_Bemaning 1") = Desc1

Desc1a = oTB1.GetResultText(oPrompt3)
iProperties.Value("Custom", "TMP_BENAMING 1") = Desc1a

Desc1a = oTB1.GetResultText(oPrompt4)
iProperties.Value("Custom", "TMP_BENAMING 2") = Desc1a

Units = oTB1.GetResultText(oPrompt5)
iProperties.Value("Custom", "TMP_Eenheden") = Units

oDatum = oTB1.GetResultText(oPrompt6)
iProperties.Value("Custom", "TMP_DATUM") = oDatum

Tol = oTB1.GetResultText(oPrompt7)
iProperties.Value("Custom", "TMP_Tolerantie") = Tol

Mat2 = oTB1.GetResultText(oPrompt8)
iProperties.Value("Custom", "TMP_MATERIAL") = Mat2

klant = oTB1.GetResultText(oPrompt9)
iProperties.Value("Custom", "TMP_Klant") = klant

oReference = oTB1.GetResultText(oPrompt10)
iProperties.Value("Custom", "TMP_Referentie") = oReference

********ERROR MESSAGE*********************
'System.ArgumentException: De Parameter Is onjuist. (Exception From HRESULT: 0x80070057 (E_INVALIDARG))
'   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
'   at Inventor.TitleBlock.GetResultText(TextBox DefinitionText)
'   at ThisRule.Main()
'   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
'   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

This is where I am at right now. I feel that I am close to the result I am looking for, however there is an error message when I run the rule. I looked it up, and it might have something to do with "Normal" tekst boxes mixed with "Prompted" ones. I have tried some solutions but all I seem to be doing it making things worse.

The error message is: 'Exception from HRESULT: 0x80070057 (E_INVALIDARG)'

 

I want to use this rule for different drawing with different titleblocks, so it might not find all the field I am searching for. But I donkt think that is the issue.

 

Any clue of what I am doing wrong? As always, any kind of help is greatly apprciated!

0 Likes
Message 11 of 18

jfildes
Enthusiast
Enthusiast

@m.verbunt wrote:
 

This is where I am at right now. I feel that I am close to the result I am looking for, however there is an error message when I run the rule. I looked it up, and it might have something to do with "Normal" tekst boxes mixed with "Prompted" ones. I have tried some solutions but all I seem to be doing it making things worse.

The error message is: 'Exception from HRESULT: 0x80070057 (E_INVALIDARG)'

 

I want to use this rule for different drawing with different titleblocks, so it might not find all the field I am searching for. But I donkt think that is the issue.

 

Any clue of what I am doing wrong? As always, any kind of help is greatly apprciated!


I'm going to guess that the problem is not having a handler to deal with other text boxes outside of what you are looking for. Since you have your criteria defined, try adding an else statement to skip the box if it doesn't match you criteria. Perhaps this will work...

 

' Find the Prompted Entry called <MATERIALS> in the Title Block
For Each defText As TextBox In titleDef.Sketch.TextBoxes
    If defText.Text = "<MATERIALS>" Then
		oPrompt = defText

	ElseIf defText.Text = "<Bemaning 1>" Then
		oPrompt2 = defText
		
	ElseIf defText.Text = "<BENAMING 1>" Then
		oPrompt3 = defText
		
	ElseIf defText.Text = "<BENAMING 2>" Then
		oPrompt4 = defText
		
	ElseIf defText.Text = "<Eenheden>" Then
		oPrompt5 = defText
		
	ElseIf defText.Text = "<DATUM>" Then
		oPrompt6 = defText
		
	ElseIf defText.Text = "<Tolerantie>" Then
		oPrompt7 = defText		
		
	ElseIf defText.Text = "<MATERIAL>" Then
		oPrompt8 = defText
		
	ElseIf defText.Text = "<Klant>" Then
		oPrompt9 = defText
		
	ElseIf defText.Text = "<Referentie>" Then
		oPrompt10 = defText

        ' Exit For <- You need to remove this line as it is exiting the loop once it finds the variable you are looking for
	Else Next 'This should skip the text box if it doesn't match your above criteria
    End If
Next 'This might need changed to "Exit For" if there is still an error since the loop now looks for matches within the "ElseIf" statements.

 

 

 

0 Likes
Message 12 of 18

jfildes
Enthusiast
Enthusiast

Ignore my last comment. I got this to work for multiple prompted entries. I hope this helps you @m.verbunt 

 

 

'Read Title Block from Active Sheet

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oTB1 As TitleBlock
oTB1 = oSheet.TitleBlock
Dim titleDef As TitleBlockDefinition
titleDef = oTB1.Definition
Dim oPrompt As TextBox
Dim oPrompt1 As TextBox
Dim oPrompt2 As TextBox
Dim oPrompt3 As TextBox
'make sure you declare all your prompts

' Find the Prompted Entry called <MATERIALS> in the Title Block For Each defText As TextBox In titleDef.Sketch.TextBoxes If defText.Text = "<Test1>" Then oPrompt1 = defText ElseIf defText.Text = "<Test2>" Then oPrompt2 = defText ElseIf defText.Text = "<Test3>" Then oPrompt3 = defText End If Next 'write prompted entry to iprop Dim T1 As String Dim T2 As String Dim T3 As String 'declare all your unique strings
T1 = oTB1.GetResultText(oPrompt1) T2 = oTB1.GetResultText(oPrompt2) T3 = oTB1.GetResultText(oPrompt3) 'set all unique strings to unique prompts
iProperties.Value("Custom", "TBT1") = T1 iProperties.Value("Custom", "TBT2") = T2 iProperties.Value("Custom", "TBT3") = T3
'set all iProperties to unique strings

 

 

Message 13 of 18

m.verbunt
Advocate
Advocate

Thanks! I will give this a go. I will report back on any progress. Not sure if I have enough time to work this out today, but will do very soon.

 

I'm really greatful for your support and help!


@jfildes wrote:

Ignore my last comment. I got this to work for multiple prompted entries. I hope this helps you @m.verbunt 

 

 

'Read Title Block from Active Sheet

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oTB1 As TitleBlock
oTB1 = oSheet.TitleBlock
Dim titleDef As TitleBlockDefinition
titleDef = oTB1.Definition
Dim oPrompt As TextBox
Dim oPrompt1 As TextBox
Dim oPrompt2 As TextBox
Dim oPrompt3 As TextBox
'make sure you declare all your prompts

' Find the Prompted Entry called <MATERIALS> in the Title Block For Each defText As TextBox In titleDef.Sketch.TextBoxes If defText.Text = "<Test1>" Then oPrompt1 = defText ElseIf defText.Text = "<Test2>" Then oPrompt2 = defText ElseIf defText.Text = "<Test3>" Then oPrompt3 = defText End If Next 'write prompted entry to iprop Dim T1 As String Dim T2 As String Dim T3 As String 'declare all your unique strings
T1 = oTB1.GetResultText(oPrompt1) T2 = oTB1.GetResultText(oPrompt2) T3 = oTB1.GetResultText(oPrompt3) 'set all unique strings to unique prompts
iProperties.Value("Custom", "TBT1") = T1 iProperties.Value("Custom", "TBT2") = T2 iProperties.Value("Custom", "TBT3") = T3
'set all iProperties to unique strings

 

 


 

Message 14 of 18

m.verbunt
Advocate
Advocate

I got it to work! I am really thankfull for the help I have been given here. I will leave my code so the next person who wants something simmular, this might give them a head start.

 

I have added 'On Error Resume Next' to cancel out any errors when a field was not found.

 

Once again a massive thank you!

 

'Read Title Block from Active Sheet

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oTB1 As TitleBlock
oTB1 = oSheet.TitleBlock
Dim titleDef As TitleBlockDefinition
titleDef = oTB1.Definition
Dim oPrompt1 As TextBox
Dim oPrompt2 As TextBox
Dim oPrompt3 As TextBox
Dim oPrompt4 As TextBox
Dim oPrompt5 As TextBox
Dim oPrompt6 As TextBox
Dim oPrompt7 As TextBox
Dim oPrompt8 As TextBox
Dim oPrompt9 As TextBox
'make sure you declare all your prompts


' Find the Prompted Entry called <MATERIALS> in the Title Block
For Each defText As TextBox In titleDef.Sketch.TextBoxes
	On Error Resume Next	
	If defText.Text = "<MATERIAL>" Then
		oPrompt1 = defText
	ElseIf defText.Text = "<DESCRIPTION 1>" Then
		oPrompt2 = defText
	ElseIf defText.Text = "<DESCRIPTION 2>" Then
		oPrompt3 = defText
	ElseIf defText.Text = "<UNITS>" Then
		oPrompt4 = defText
	ElseIf defText.Text = "<DATE>" Then
		oPrompt5 = defText
	ElseIf defText.Text = "<TOLERANCES>" Then
		oPrompt6 = defText
	ElseIf defText.Text = "<MATERIALS>" Then
		oPrompt7 = defText
	ElseIf defText.Text = "<CUSTOMERS>" Then
		oPrompt8 = defText
	ElseIf defText.Text = "<REFERENCE>" Then
		oPrompt9 = defText
	End If
Next

'write prompted entry to iprop
Dim T1 As String
Dim T2 As String
Dim T3 As String
Dim T4 As String
Dim T5 As String
Dim T6 As String
Dim T7 As String
Dim T8 As String
Dim T9 As String
'Declare all your unique strings

T1 = oTB1.GetResultText(oPrompt1)
T2 = oTB1.GetResultText(oPrompt2)
T3 = oTB1.GetResultText(oPrompt3)
T4 = oTB1.GetResultText(oPrompt4)
T5 = oTB1.GetResultText(oPrompt5)
T6 = oTB1.GetResultText(oPrompt6)
T7 = oTB1.GetResultText(oPrompt7)
T8 = oTB1.GetResultText(oPrompt8)
T9 = oTB1.GetResultText(oPrompt9)
'set all unique strings to unique prompts

iProperties.Value("Custom", "TMP_MATERIAL") = T1
iProperties.Value("Custom", "TMP_DESCRIPTION  1") = T2
iProperties.Value("Custom", "TMP_DESCRIPTION  2") = T3
iProperties.Value("Custom", "TMP_UNITS") = T4
iProperties.Value("Custom", "TMP_DATUM") = T5
iProperties.Value("Custom", "TMP_TOLERANCES") = T6
iProperties.Value("Custom", "TMP_MATERIALS") = T7
iProperties.Value("Custom", "TMP_CUSTOMERS") = T8
iProperties.Value("Custom", "TMP_REFERENCE") = T9
'Set all iProperties To unique strings
Message 15 of 18

jfildes
Enthusiast
Enthusiast

That's great @m.verbunt! I'm glad you were able to figure it out! Good luck in your future endeavors. 

 

0 Likes
Message 16 of 18

dliteful
Contributor
Contributor

This works almost perfect for me.  Thank you for sharing your code.

 

Some of our files have some of the prompted text added to the iProperties with correct values.  Setting the iProperties overrides those values.  I tried using Try/Catch instead, but it didn't seem to like the string.  Error message below.  Any input would be greatly appreciated.

 

Error in rule: Rule5, in document: TEST-CHAIN GUIDE.idw

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.TitleBlock.GetResultText(TextBox DefinitionText)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 17 of 18

m.verbunt
Advocate
Advocate

I have added 'TMP_ ' to the named Custom Properties to avoid this issue. In another rule I compare these to the ipropety fields that these values need to be pushed to. If an iproperty value is already present, a dialog will pop up, asking me what data to keep, from the TMP_ or the Original. When all is completed, and tranfered another rule will delete all  custom TMP_ property fields. However I do run the 'delete TMP_' rule manualy, as I always want to check if things went according to plan.

0 Likes
Message 18 of 18

jgonzalezG3NUF
Observer
Observer

I was wondering if anybody ran into the problem of not getting any errors after runing the rule but this one still doesn't affect the titleblock. Also what is the correct environment to make it work? you are trying to copy sheet 1 title block entries into sheet 2 title correct? 

0 Likes