iLogic, Titleblock and Prompted Entry

iLogic, Titleblock and Prompted Entry

Anonymous
Not applicable
4,346 Views
17 Replies
Message 1 of 18

iLogic, Titleblock and Prompted Entry

Anonymous
Not applicable

Hi,

I'm trying to write a rule which will create a new sheet with the right Titleblock.

I couldn't manage to find a way to apply the TitleBlock because it has Prompted Entry.

I really need them, and I found in this example that we should be able to manage the Prompted Entry when applying a TitleBlock with iLogic : http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-389C7661-CA66-437B-95A4-28F2A11A7A57

Here my simplified code :

'Create new sheet
NewSheet = oSheets.Add(DrawingSheetSizeEnum.kADrawingSheetSize,PageOrientationTypeEnum.kLandscapePageOrientation,NewSheetName)

'Add border
NewSheet.AddBorder("Custom border")

'Add TitleBlock
'     1st : create the array for Prompted Entry
sPromptStrings = New String(){"TEST"}
'     2nd : add the TitleBlock
NewSheet.AddTitleBlock("Custom TitleBlock", ,sPromptStrings)

Here is the documentation of an Inventor Sheet with the AddTitleBlock method : http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-7BCBBA98-FFBE-45CD-AEEE-00FFD9AC4AEA

What did I miss?

Thanks,

Math

Note: I use Inventor 2012

Accepted solutions (1)
4,347 Views
17 Replies
Replies (17)
Message 2 of 18

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

 

Hoping that below iLogic code may be helpful.

'Create new sheet
NewSheet = oSheets.Add(DrawingSheetSizeEnum.kADrawingSheetSize,PageOrientationTypeEnum.kLandscapePageOrientation,NewSheetName)

'Add border
NewSheet.AddBorder("Custom border")
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

    ' Obtain a reference to the desired border defintion.
Dim oTitleBlockDef As TitleBlockDefinition
oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item("Custom TitleBlock") 'Add TitleBlock ' 1st : create the array for Prompted Entry
Dim sPromptStrings(1) As String
sPromptStrings(0) = "Text"
' 2nd : add the TitleBlock NewSheet.AddTitleBlock(oTitleBlockDef , ,sPromptStrings)

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 18

Anonymous
Not applicable

Hi @chandra.shekar.g

Thanks for your support.

I tried your code, but I still have the same error. I can't add the TitleBlock.

 

0 Likes
Message 4 of 18

JamieVJohnson2
Collaborator
Collaborator

Are you sure you have one item in the string array per each prompted entry in the Titleblock definition, no more no less?

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 5 of 18

Anonymous
Not applicable

Yep, I tried with just one prompted entry, to be sure, but with no luck.

0 Likes
Message 6 of 18

JamieVJohnson2
Collaborator
Collaborator

Looking into my wayback machine, I did successfully insert a Titleblock in mass (for swapping titleblocks, which can be done by the drawing resource transfer wizard today), and still have the remmed code.  Perhaps something in here can help you figure it out.

 

'get prompted data

''reference from other code - Dim dwg As Inventor.DrawingDocument = invdoc
    '                                    ' Dim promptList As Dictionary(Of String, String) = GetPromptedEntriesFromTitleBlock(tblock)
    '                                    Dim existTDF As TitleBlockDefinition = tblock.Definition
    '                                    'remove titleblocks
    '                                    sht.TitleBlock.Delete()
    '                                    existTDF.Name = existTDF.Name & "-Old"
    '                                    'add new titleblock
    '                                    If newTDF IsNot Nothing Then
    '                                        newTDF.CopyTo(dwg)
    '                                    End If
    '                                    Dim newTBD As TitleBlockDefinition = GetTitleBlockDefinition(strNewTitleblock, dwg)
    '                                    ' Dim ps() As String = promptList.Values.ToArray
    '                                    'replace promped data
    '                                    ' sht.AddTitleBlock(newTBD, , ps)
    '                                    'PlacePromptedEntriesToTitleBlock(sht.TitleBlock, ps)

 

 

    'Public Function GetPromptedEntriesFromTitleBlock(tb As TitleBlock) As Dictionary(Of String, String)
    '    Dim list As New Dictionary(Of String, String)
    '    For Each textB As TextBox In tb.Definition.Sketch.TextBoxes
    '        Dim xml As New DOMDocument60
    '        xml.loadXML(textB.FormattedText)
    '        ' Look for prompted entry
    '        Dim node As IXMLDOMNode= xml.selectSingleNode("Prompt")
    '        If Not node Is Nothing Then
    '            list.Add(node.text, tb.GetResultText(textB))
    '        End If
    '        xml = Nothing
    '    Next
    '    Return list
    'End Function
    'Public Sub PlacePromptedEntriesToTitleBlock(tb As TitleBlock, values As Dictionary(Of String, String))
    '    For Each textB As TextBox In tb.Definition.Sketch.TextBoxes
    '        Dim xml As New DOMDocument60
    '        xml.loadXML(textB.FormattedText)
    '        Dim node As IXMLDOMNode = xml.selectSingleNode("Prompt")
    '        If node IsNot Nothing Then
    '            For Each nodeName As String In values.Keys
    '                If node.text = nodeName Then
    '                    tb.SetPromptResultText(textB, values(nodeName))
    '                End If
    '            Next
    '        End If
    '    Next
    'End Sub
Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 7 of 18

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please provide drawing document to investigate? please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 18

Anonymous
Not applicable

Hi @chandra.shekar.g,

I attached the drawing and the part.

I can't attach the iLogicVb file, so here the complete code :

'On vérifie que le document est une mise en plan
If Not ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
	MessageBox.Show("Ce document n'est pas une mise en plan", "Ajout non-conformité", MessageBoxButtons.OK, MessageBoxIcon.Warning)
	Return
End If

'On vérifie que le dessin actif contient un vue avant de poursuivre en cherchant le chemin du modèle
Try
	modelName = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName)
Catch
	Return
End Try

oSheets = ThisApplication.ActiveDocument.Sheets
NCcounter = 1

i = 1
While (i <= oSheets.Count)
	If Left(oSheets(i).Name,2) = "NC" Then
		NCcounter = NCcounter + 1
	End If
	i = i + 1
End While

NewSheetName = "NC" & NCcounter

NewSheet = oSheets.Add(DrawingSheetSizeEnum.kADrawingSheetSize,PageOrientationTypeEnum.kLandscapePageOrientation,NewSheetName)

NewSheet.ExcludeFromCount = True
NewSheet.ExcludeFromPrinting = True
NewSheet.AddBorder("Custom Border")

'En attente de solution pour ajouter automatiquement le cartouche
'MessageBox.Show("Veuillez ajouter manuellement le cartouche" & vbCrLf & "'Non-conformity TitleBlock'", "Ajout non-conformité", MessageBoxButtons.OK, MessageBoxIcon.Information)

oDrawDoc = ThisApplication.ActiveDocument
    ' Obtain a reference to the desired border defintion.
Dim oTitleBlockDef As TitleBlockDefinition
oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item("Non-conformity TitleBlock TEST")

'Add TitleBlock
'     1st : create the array for Prompted Entry
Dim sPromptStrings(1) As String
sPromptStrings(0) = "TEST"
'     2nd : add the TitleBlock
NewSheet.AddTitleBlock(oTitleBlockDef , ,sPromptStrings)
'NewSheet.AddTitleBlock(oTitleBlockDef)

For my tests, I use the Non-conformity TitleBlock TEST, but the goal is to use the Non-conformity TitleBlock at the end.

Regards,

Math

0 Likes
Message 9 of 18

JamieVJohnson2
Collaborator
Collaborator

https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/arrays/

You are declaring string(1), which gives you a 2 compartment array.

Inventor object arrays are 1 based (true), but iLogic/VB.Net/VBA arrays are 0 based.  You must carefully juggle between the two.

Another topic is your use of the while loop.  It appears to originate from C programming language.  Its certainly not wrong, but you can simplify using the For loop.

 

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-next-statemen...

 

For i as integer = 1 to array.count '(implied auto step of i=i+1 each iteration)

'use i as your counter/index like you always did, no need to add up index, the for loop does on its own.

Next

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 10 of 18

Anonymous
Not applicable

Hi @JamieVJohnson2,

I already tried both solution for the array sized, as I wasn't sure.

So I tested again with 2 prompted field and created a string(1) array.

I carefully named the array with same name of the prompted fields names, and in the right order.

I still have the same error.

Regarding the While, I changed it for the For... Next loop. Thanks.

0 Likes
Message 11 of 18

JamieVJohnson2
Collaborator
Collaborator

I see that your Non-conformity Titleblock as 12 prompted entries (No Project, No Piece, Fournisseur, No Commande...), and one dynamic property (Part Number).

  you will need an array of 12 elements

array(11) specifies a 0 based array with 0-11 elements aka 12 elements.

To simplify, or make more complex), you could use a list(of string)

dim entries as new list(of string)

entries.add("No Project Value" or a variable like NoProjectValue)'No Project

entries.add("No Piece Value")'No Piece

entries.add("Fournisseur Value")'Fournisseur

all 12 values, then create array like this

entries.toArray

it will output a 12 element string array (or whatever size you give it by count of entities), and you can do this inline with the Titleblock command.

 

One other question.  You are deleting the original titleblock on the sheet BEFORE adding a new one right?  That would be an obvious reason for Inventor to throw an error.

 

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 12 of 18

Anonymous
Not applicable

The titleblock "Non-conformity TitleBlock" is the good one I want to be able to use.

But in my tests, I use the title block "Non-conformity TitleBlock TEST" with just only 1 prompted entry. I modified it since to include a 2nd prompted entry to try the "Dim sPromptStrings(1) As String".

So I don't think the error come form this.

 

Regarding the removing of the titleblock, I tried it too, but it didn't change anything as I'm creating a new sheet without border and titleblock.

 

I also tried you solution for the list : "Dim sPromptStrings as New list(Of String)" with no luck.

 

So for now I'm still stuck with the original problem.

 

One thing I remarked after working with iLogic is that the error log is not very usefull some time. It doesn't really explain the problem. For exemple, the error about the problem above is :

Paramètre incorrect. (Exception de HRESULT : 0x80070057 (E_INVALIDARG))
0 Likes
Message 13 of 18

HermJan.Otterman
Advisor
Advisor
Accepted solution

create a new rule in the drawing.

 

past this some altered code from the Inventor API help in it, and run it.

 

it will change and fill your title block on the third sheet:

 

 

SyntaxEditor Code Snippet

 Sub main
    ' 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 defintion.
    Dim oTitleBlockDef As TitleBlockDefinition
     oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item("Non-conformity TitleBlock")

    Dim oSheet As Sheet
     oSheet = oDrawDoc.Sheets(3) 'Sheet 3 !

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


    ' This title block definition contains one prompted string input.  An array
    ' must be input that contains the strings for the prompted strings.
    Dim sPromptStrings(11) As String
	
    sPromptStrings(0) = "String 00"
    sPromptStrings(1) = "String 1"
    sPromptStrings(2) = "String 2"
	sPromptStrings(3) = "String 3"
	sPromptStrings(4) = "String 4"
	sPromptStrings(5) = "String 5"
	sPromptStrings(6) = "String 6"
	sPromptStrings(7) = "String 7"
	sPromptStrings(8) = "String 8"
	sPromptStrings(9) = "String 9"
	sPromptStrings(10) = "String 10"
	sPromptStrings(11) = "String 011"

	

    ' Add an instance of the title block definition to the sheet.
    Dim oTitleBlock As TitleBlock
    oTitleBlock = oSheet.AddTitleBlock(oTitleBlockDef, , sPromptStrings)
End Sub

change the number after sheet (3) to put it on an other sheet

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 14 of 18

Anonymous
Not applicable

Hi @HermJan.Otterman

I tried your code, and it works!

I will check what differ from mine, but it looks very similar. I don't understand.

Thanks!

0 Likes
Message 15 of 18

Anonymous
Not applicable

Hi all,

I finally found the problem.

I didn't declare the NewSheet as Sheet.

So here the functional code:

'On vérifie que le document est une mise en plan
If Not ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
	MessageBox.Show("Ce document n'est pas une mise en plan", "Ajout non-conformité", MessageBoxButtons.OK, MessageBoxIcon.Warning)
	Return
End If

'On vérifie que le dessin actif contient un vue avant de poursuivre en cherchant le chemin du modèle
Try
	modelName = IO.Path.GetFileName(ThisDoc.ModelDocument.FullFileName)
Catch
	Return
End Try

oSheets = ThisApplication.ActiveDocument.Sheets
NCcounter = 1

i = 1
While (i <= oSheets.Count)
	If Left(oSheets(i).Name,2) = "NC" Then
		NCcounter = NCcounter + 1
	End If
	i = i + 1
End While

NewSheetName = "NC" & NCcounter

Dim NewSheet As Sheet
NewSheet = oSheets.Add(DrawingSheetSizeEnum.kADrawingSheetSize,PageOrientationTypeEnum.kLandscapePageOrientation,NewSheetName)

NewSheet.ExcludeFromCount = True
NewSheet.ExcludeFromPrinting = True
NewSheet.AddBorder("Custom Border")

'En attente de solution pour ajouter automatiquement le cartouche
'MessageBox.Show("Veuillez ajouter manuellement le cartouche" & vbCrLf & "'Non-conformity TitleBlock'", "Ajout non-conformité", MessageBoxButtons.OK, MessageBoxIcon.Information)

oDrawDoc = ThisApplication.ActiveDocument
    ' Obtain a reference to the desired border defintion.
Dim oTitleBlockDef As TitleBlockDefinition
oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item("Non-conformity TitleBlock TEST")

'Add TitleBlock
'     1st : create the array for Prompted Entry
Dim sPromptStrings(1) As String
sPromptStrings(0) = "TEST"
'     2nd : add the TitleBlock
NewSheet.AddTitleBlock(oTitleBlockDef , ,sPromptStrings)
'NewSheet.AddTitleBlock(oTitleBlockDef)

Thanks everyone for helping me!

Message 16 of 18

marcin_bargiel
Advocate
Advocate

Simple problem :

I got 3 prompted entry, added when creating new sheet.

<type1> (='whatever1') , <type2>(='whatever2' ) , <type3>(='whatever3' )

Now i want to set iProperties with one of those prompted entry :

iProperties.Value("Project", "Project") = <type1> etc.

 

How to do this ?

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 17 of 18

Anonymous
Not applicable

I will have to do the same for a new script, but for now I don't know how to do that.

You will be better to create a new post as it's not really the same problem.

Math

0 Likes
Message 18 of 18

prussellZXB3F
Enthusiast
Enthusiast

Thanks for the prompted entry code, I had to use different resources and methods to get it to work but thought I'd post for the next soul passing this way

 

 

 

 

 

Function GetPromptedEntries(tb As TitleBlock) As Dictionary(Of String, String)
	Dim list As New Dictionary(Of String, String)
	For Each tBox As Inventor.TextBox In tb.Definition.Sketch.TextBoxes
		Dim xmlDoc As New XmlDocument
		xmlDoc.LoadXml("<Root>" & tBox.FormattedText & "</Root>")
		Dim node As XmlNode = xmlDoc.SelectSingleNode("Root/Prompt")
		If node IsNot Nothing Then list.Add(node.InnerText, tb.GetResultText(tBox))
	Next
	return list
End function

 

 

 

 

0 Likes