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: 

Editing Prompted Entry values with iLogic

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
AlexFielder
5619 Views, 14 Replies

Editing Prompted Entry values with iLogic

Hi Folks,

 

I have been attempting to automate some prompted entry (PE) values using iLogic and the SetPromptResultText command.

 

The command works on the customer-supplied template I have if I create a new PE called <DELETEME> - my code also works on this new PE even if I delete the "<" & ">" from either end of the string so it becomes "DELETEME".

 

The command doesn't work on the customer supplied fields of "PURPOSE OF ISSUE" & "PROJECT REF No" but if I add < & > to either end (so they become "<PROJECT REF No>" & "<PURPOSE OF ISSUE>" respectively) and modify my code to look for that instead, lo and behold it works.

 

Can anybody shed any light on why it works with the "<" & ">" on the ends of the string but not without?

 

My guess is that the "<" & ">" allow the PE to have spaces and without it Inventor 2013 throws the dummy in the dirt and refuses to play nice! - Just tested that theory and it's clearly cobblers...

 

Thanks,

 

Alex.

 

Edit: Here's the sub-routine I wrote (with the working "<" & ">" still in place) before anyone asks to see it:

 

Sub UpdatePromptedEntries(oDoc As DrawingDocument)
'assumes the oDoc is activated
Dim oPromptEntry
Dim actSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
'For Each oSheet In ThisApplication.ActiveDocument.Sheets
For Each oSheet In oDoc.Sheets
	'MessageBox.Show(oSheet.Name, "Sheet Name")
    ActiveSheet=ThisDrawing.Sheet(oSheet.Name)
    If oSheet.TitleBlock Is Nothing Then Exit Sub
	'MessageBox.Show("Title OKAY!", "Go Gadget Go")
    oTitleBlock=oSheet.TitleBlock
    oTextBoxes=oTitleBlock.Definition.Sketch.TextBoxes
    For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes
		'comment this ASAP otherwise it will break! ALOT!
'		If Not oTitleBlock.GetResultText(oTextBox) = String.Empty Then
'			MessageBox.Show(oTitleBlock.GetResultText(oTextBox), oTextBox.Text)
'		Else
'			MessageBox.Show(oTextBox.Text, "Empty PE Found!")
'		End If
		Select oTextBox.Text
			Case "<PROJECT REF No>":
				oPromptEntry = ThisProjectNo
				Call oTitleBlock.SetPromptResultText(oTextBox, oPromptEntry)
			Case "<PURPOSE OF ISSUE>":
				oPromptEntry = ThisPurposeForIssue
				'MessageBox.Show(oTitleBlock.GetResultText(oTextBox), "PURPOSE OF ISSUE")
				MessageBox.Show("BEFORE Intended Purpose for issue: " & ThisPurposeForIssue, "PURPOSE OF ISSUE")
				Call oTitleBlock.SetPromptResultText(oTextBox, oPromptEntry)
				MessageBox.Show("AFTER Intended Purpose for issue: " & ThisPurposeForIssue, "PURPOSE OF ISSUE")				
			Case "DELETEME":
				oPromptEntry = "BUGGER ME IT WORKS!"
				Call oTitleBlock.SetPromptResultText(oTextBox, oPromptEntry)
			Case "DELETE ME":
				oPromptEntry = "WTF DUDES?"
				Call oTitleBlock.SetPromptResultText(oTextBox, oPromptEntry)
		End Select
    Next
Next
actSheet.Activate
InventorVb.DocumentUpdate()
End Sub

 

14 REPLIES 14
Message 2 of 15
adam.nagy
in reply to: AlexFielder

Hi Alex,

 

I could not reproduce the issue in Inventor 2014. Is that the version you are using?

 

I created a Prompted Entry in the title block with "PURPOSE OF ISSUE" and one with "<PURPOSE OF ISSUE>" and the code replaced both.

 

Could you please verify that in your drawing the Text property of those text boxes are what you think they are? E.g. from VBA? http://adndevblog.typepad.com/manufacturing/2013/10/discover-object-model.html

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 15
AlexFielder
in reply to: adam.nagy

Hi Adam,

 

I am using Inventor 2013 for this although (with any luck) we will be moving to 2014 in January.

 

I've been thinking that perhaps the issue is that the drawing border provided to us will have originated in Inventor 2011 with a distinct possibility that the text properties were copied in from an AutoCAD border.

 

I will do what you suggest and convert my iLogic to vba for the purposes of debugging - I don't know why I didn't think of that sooner.

 

When I have something more concrete for you to go on I'll reply here.

 

Thanks,

 

Alex.

Message 4 of 15
AlexFielder
in reply to: AlexFielder

I've done as you suggested Adam, and after debugging with VBA it seems the issue I was having stems from the fact that the template has two pieces of text called "PURPOSE OF ISSUE" one of which is a prompted entry (PE), the other is not.

 

Because the iLogic code gets to the non-prompted entry before the PE it throws an error. simply adding an "On error Resume Next" during the textbox loop seems to solve the issue:

 

Sub UpdatePromptedEntries(oDoc As DrawingDocument)
'assumes the oDoc is activated
Dim oPromptEntry
Dim actSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
'For Each oSheet In ThisApplication.ActiveDocument.Sheets
For Each oSheet In oDoc.Sheets
    ActiveSheet=ThisDrawing.Sheet(oSheet.Name)
    If oSheet.TitleBlock Is Nothing Then Exit Sub
    oTitleBlock=oSheet.TitleBlock
    oTextBoxes=oTitleBlock.Definition.Sketch.TextBoxes
    For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes
		'comment this ASAP otherwise it will break! ALOT!
'		If Not oTitleBlock.GetResultText(oTextBox) = String.Empty Then
'			MessageBox.Show(oTitleBlock.GetResultText(oTextBox), oTextBox.Text)
'		Else
'			MessageBox.Show(oTextBox.Text, "Empty PE Found!")
'		End If
On Error Resume Next
		If otextbox.Text <>"" Then
			Select oTextBox.Text
				Case "PROJECT REF No":
					oPromptEntry = ThisProjectNo
					Call oTitleBlock.SetPromptResultText(oTextBox, oPromptEntry)
				Case "PURPOSE OF ISSUE":
					oPromptEntry = ThisPurposeForIssue
					'MessageBox.Show(oTitleBlock.GetResultText(oTextBox), "PURPOSE OF ISSUE")
					MessageBox.Show("BEFORE Intended Purpose for issue: " & ThisPurposeForIssue, "PURPOSE OF ISSUE")
					Call oTitleBlock.SetPromptResultText(oTextBox, oPromptEntry)
					MessageBox.Show("AFTER Intended Purpose for issue: " & ThisPurposeForIssue, "PURPOSE OF ISSUE")				
				Case "DELETEME":
					oPromptEntry = "BUGGER ME IT WORKS!"
					Call oTitleBlock.SetPromptResultText(oTextBox, oPromptEntry)
				Case "DELETE ME":
					oPromptEntry = "WTF DUDES?"
					Call oTitleBlock.SetPromptResultText(oTextBox, oPromptEntry)
			End Select
		End If
    Next
Next
actSheet.Activate
InventorVb.DocumentUpdate()
End Sub

 All this could probably have been avoided if the PE definitions had been named differently from static text in the border.

 

Hopefully this will help someone else avoid the same pitfall.

 

Cheers,

 

Alex.

Message 5 of 15
adam.nagy
in reply to: AlexFielder

I'm glad you found the issue.

I guess that's exactly why placing the name of the Prompted Entry inside a < & > became a convention that your customer should follow too.



Adam Nagy
Autodesk Platform Services
Message 6 of 15
warrentdo
in reply to: adam.nagy

Hello, I know that this is a long shot but will this sode work with invneotr 2011?

I have tried but i am really struggling to get it to work.

Do you still have a sample dwg that you had it working with?

 

Thank you in advance,

 

Regards,

 

WArren.

Message 7 of 15
forbillian
in reply to: adam.nagy

Hi Adam,

 

I have been trying for a couple of days to use a similar method - posted in this thread - but to add/edit Prompted values to a Border (not a titleBlock) in my Drawing Sheet.

 

Where I am running into difficulty is defining the last line in the following code.  I have been able to use this 

add custom border code and successfully apply the prompted values but I need to simply change the values in the

existing border - without having to add a new border each time.  I cant seem get the syntax right though I think

it may need to look like this?:

oBorder.Definition.Sketch.Textboxes

.

 

Any help would be much appreciated.

 

Sub Main InsertCustomBorderOnSheet()
' Set a reference to the drawing document.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument 

' Obtain a reference to the desired border definition.
Dim oBorderDef As BorderDefinition
 oBorderDef = oDrawDoc.BorderDefinitions.Item("Border")

Dim oSheet As Sheet
 oSheet = oDrawDoc.ActiveSheet

' Check to see if the sheet already has a border and delete it if it does.'If Not oSheet.Border Is Nothing Then'oSheet.Border.Delete'End If

' This border definition contains one prompted string input. An array' This line must show the exact number of Prompted Strings in the Border
Dim sPromptStrings(0 To 1) As String
sPromptStrings(0) = "WHIM"
sPromptStrings(1) = "WHAM"


' Add an instance of the border definition to the sheet.
Dim oBorder As Border
'LINE 28 IS WHERE i AM HAVING TROUBLE
oBorder = oSheet.AddBorder(oBorderDef, sPromptStrings)  'THIS LINE LINE WORKS FOR INSERTING BORDER
MsgBox("WORKS UPTO HERE BUT I WANT TO CHANGE THE sPromptStrings WITHOUT deleting & adding the Border again")
End Sub

 

Message 8 of 15
adam.nagy
in reply to: forbillian

The above solution from @AlexFielder seems to be doing exactly that - just instead of calling TitleBlock.SetPromptResultText you would be calling Border.SetPromptResultTexthttp://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-28ABDF5C-55D4-4F22-AF7B-79C883F00407  

 

Did you try that?



Adam Nagy
Autodesk Platform Services
Message 9 of 15
forbillian
in reply to: adam.nagy

Thanks for the response Adam,

 

Yes I was able to get it working using a similar code to @AlexFielder    

 

Here is what I have working as an example if it helps anyone for Borders.

 

Sub Main UpdateBorderFields()

oDoc = ThisDoc.Document

Dim oSheets As Sheets
Dim oSheet As Sheet

Dim oBorder As Border

Dim oTextBox As TextBox

Dim oCurrentSheet
oCurrentSheet = oDoc.ActiveSheet.Name

Dim oPromptEntry

i = 0
For Each oSheet In oDoc.Sheets
  i = i+1
  'activate the sheet
  ThisApplication.ActiveDocument.Sheets.Item(i).Activate
 
	'REFERENCE SHEET BORDER
	oBorder = oSheet.Border

	
	
    oTextBoxes = oBorder.Definition.Sketch.TextBoxes
    For Each oTextBox In oBorder.Definition.Sketch.TextBoxes
	Select oTextBox.Text
		Case "<DESIGNER>"
			oPromptEntry  = InputBox("Enter the Part Number: ", "iLogic " & oSheet.Name, iProperties.Value("Summary", "Author"))
			Call oBorder.SetPromptResultText(oTextBox, oPromptEntry)
		
		
		Case "<CLIENT DRAWING TITLE No1>"
			Call oBorder.SetPromptResultText(oTextBox, "XXXXXXX")	
						MsgBox(sData)
			


		End Select
	Next	
Next

ThisApplication.ActiveDocument.Sheets.Item(oCurrentSheet).Activate

End Sub

 

Message 10 of 15
forbillian
in reply to: adam.nagy

Hi Adam,

 

I am progressing in my pursuit of Border Prompt Text manipulation, however I am attempting to add a Border

without knowing or needing to know the exact number of sprompt strings which are contained within the border.

 

I have managed to be able to reference a border within my drawing (prior to adding it to a sheet) & return

a count of how many prompt text values are contained which I am sure I can somehow use to loop through any possible spromptstrings prior to adding this border.  Here is the method for returning a count:

 

Sub Main ListDrawingResources()
    Dim drawDoc As DrawingDocument
     drawDoc = ThisApplication.ActiveDocument
    
       
    Debug.Print("")
    Debug.Print("TRIAL")
    Dim borderDef As BorderDefinition
    For Each borderDef In drawDoc.BorderDefinitions
        Debug.Print(borderDef.Name)
            MsgBox(borderDef.Name)
    Next


If    borderDef.Name = "TRIAL" Then

Dim oBorderDef As BorderDefinition
     oBorderDef = drawDoc.BorderDefinitions.Item("TRIAL")

Dim oTextBox As TextBox

Dim oTextBoxes As TextBoxes = oBorderDef.Sketch.TextBoxes


If borderDef.Name = "TRIAL" Then



For Each oTextBox In oTextBoxes

    
     Dim I 

    For I = 1 To oBorderDef.Sketch.TextBoxes.Count
    
'          oEachText = oBorderDef.Sketch.TextBoxes(I)'        If (oEachText.Text = "") Then'            ' found the prompt text we want to copy'              oPromptText = oEachText'            Exit For'        End If
    Next I
Next

    MsgBox("IN THIS BORDER: " & borderDef.Name & " THERE ARE: " & oBorderDef.Sketch.TextBoxes.Count & " PROMPT VALUES")
    
    End If
    
 
    End If




End Sub

 

What I am trying to attempt is use this 'count' number to define the prompt strings no which are needed when adding the referenced border e.g. this next part of the code:

 

Dim sPromptStrings(0 To oBorderDef.Sketch.TextBoxes.Count) As String
sPromptStrings(I) = ""
sPromptStrings(1) = ""
sPromptStrings(2) = ""



Dim oBorder As Border

oBorder = oSheet.AddBorder(oBorderDef,sPromptStrings)')  'THIS LINE LINE WORKS FOR INSERTING BORDER

 Any pointers would be much appreciated.

 

Thanks Adam

Message 11 of 15

@forbillian,

 

For more understanding, can you please explain reproducible steps with model data? please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 12 of 15

Thanks Chandra,

 

Please See attached Inventor Drawing which includes A Rule that Works & a Rule I am having problems with.

 

I can add a border if I know how many prompts are in the border, but I am trying to add a border with any number of prompts by getting a count of the prompts before I add the border.

 

Please see attached i am using inventor 2018 version.

 

 

 

 

Message 13 of 15

@forbillian,

 

In the below iLogic code, variable "sPromptStrings" is just a string. Which is incorrect parameter to add border. String array is valid parameter to add border into sheet.

 

Dim myArrayList As New ArrayList
Dim j As Long
'Dim sPromptStrings(j) As String
Dim sPromptStrings As String
		For j = 0 To 1
			sPromptStrings = "sPromptStrings(" & j & ")" 
			
			myArrayList.Add(sPromptStrings)
			MessageBox.Show(myArrayList.Item(j) & ": was found!", "iLogic")

		Next j


' Add an instance of the border definition to the sheet.
Dim oBorder As Border
oBorder = oSheet.AddBorder(oBorderDef, sPromptStrings)

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 14 of 15

@chandra.shekar.g 

 

Thankyou Chandra for your assistance.

 

I am getting an error at this line 

oBorder = oSheet.AddBorder(oBorderDef, sPromptStrings)

I suspect it is because we have not given a value to each string & I am wondering if the following line

is naming each string in the array or is it giving each string in the array a value?

 

For j = 0 To 1
			sPromptStrings = "sPromptStrings(" & j & ")" 

For example the original code for giving each string a value was this:

Dim sPromptStrings(0 To 1) As String
sPromptStrings(0) = "TEXT"
sPromptStrings(1) = "TEXT"

In addition to our original code do I need to iterate through each string in the array and give it a value.

 

e.g. for each sPromptStrings in myArrayList.....................sPromptStrings(j) = "TEXT"  etc?

 

Thanks Chandra - much appreciated

Message 15 of 15

For anyone that might need this code to insert a border with any number of prompts

please find the code I have got to work.  Thanks to @chandra.shekar.g for pointing me in the right direction.

 

Sub Main CountBorderPromptsInDocument()
    
Dim drawDoc As DrawingDocument
     drawDoc = ThisApplication.ActiveDocument
    
       
    Debug.Print("")
    Debug.Print("TRIAL")
    Dim borderDef As BorderDefinition
    For Each borderDef In drawDoc.BorderDefinitions
		If    borderDef.Name = "TRIAL" Then
        Debug.Print(borderDef.Name)
            'MsgBox(borderDef.Name)
		End If
    Next



Dim oBorderDef As BorderDefinition
     oBorderDef = drawDoc.BorderDefinitions.Item("TRIAL")



Dim oTextBox As TextBox
Dim oTextBoxes As TextBoxes = oBorderDef.Sketch.TextBoxes

For Each oTextBox In oTextBoxes
     Dim I 
	    For I = 1 To oBorderDef.Sketch.TextBoxes.Count
	 Next I
Next


'MESSAGE INDICATING HOW MANY PROMPT VALUES EXIST
    MsgBox("IN THIS BORDER: " & borderDef.Name & " THERE ARE: ' " & oBorderDef.Sketch.TextBoxes.Count & " ' PROMPT VALUES")
    
iProperties.Value("Custom","PromptNO") = (oBorderDef.Sketch.TextBoxes.Count-1)

Call InsertCustomBorderOnSheet1()  'THIS RULE WORKS
    

End Sub


Private Sub InsertCustomBorderOnSheet1()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    
    ' Obtain a reference to the desired border definition.
    Dim oBorderDef As BorderDefinition
     oBorderDef = oDrawDoc.BorderDefinitions.Item("TRIAL")
     
     'gather the current sheet name
    Dim oCurrentSheet
    oCurrentSheet = oDrawDoc.ActiveSheet.Name
    
    Dim oSheet As Sheet
    oSheet = oDrawDoc.ActiveSheet
    
    'step through each sheet
i = 0
For Each oSheet In oDrawDoc.Sheets
  i = i+1
  'activate the sheet
  ThisApplication.ActiveDocument.Sheets.Item(i).Activate
    
    ' Check to see if the sheet already has a border and delete it if it does.
    If Not oSheet.Border Is Nothing Then
        oSheet.Border.Delete
    End If

 '**********************************************************************************************************************   

' GET THE NUMBER OF PROMPTS FROM THE PREVIOUS CODE COUNT
Dim PromptNO As Integer = iProperties.Value("Custom","PromptNO")

Dim sPromptStrings(0 To PromptNO) As String
'SAME ENTRY FOR EACH PROMPT

For j = 0 To PromptNO
	
	sPromptStrings(j) = "PROMPTS WORK"
'sPromptStrings(j) = "" 'if you want each prompt to be blank
Next j ' Add an instance of the border definition to the sheet. Dim oBorder As Border oBorder = oSheet.AddBorder(oBorderDef, sPromptStrings) '********************************************************************************************************************** Next ThisApplication.ActiveDocument.Sheets.Item(oCurrentSheet).Activate End Sub

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

Post to forums  

Autodesk Design & Make Report