Ilogic replace title block

Ilogic replace title block

Anonymous
Not applicable
1,159 Views
4 Replies
Message 1 of 5

Ilogic replace title block

Anonymous
Not applicable

Hi I've a msg box asking the user what kind of drawing is he making.

If the answer is yes (6) then Inventor will change the styles and delete the current title block and »»» replaces by an other with the name Ferramentas and it does delete the current one but does not place the other named Ferramentas, any ideia why?

TIA

 

 

Dim i As String
i = MessageBox.Show("Vai efectuar o desenho de uma ferramenta?", "ALUALPHA", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)

If i = "6" Then
		' mudar os estilos para ferramentas
	Dim oDoc As DrawingDocument
    oDoc = ThisApplication.ActiveDocument
	oDoc.StylesManager.ActiveStandardStyle = oDoc.StylesManager.StandardStyles("Alualpha Ferramentas")
	' defenir os title blocks
	Dim oTitleBlockDef1 As TitleBlockDefinition
	oTitleBlockDef1 = oDoc.TitleBlockDefinitions. _
    Item("Alualpha")
	Dim Val1 As Boolean = oTitleBlockDef1.IsReferenced
	
	Dim oTitleBlockDef2 As TitleBlockDefinition
	oTitleBlockDef2 = oDoc.TitleBlockDefinitions. _
    Item("Ferramentas")
	Dim Val2 As Boolean = oTitleBlockDef2.IsReferenced

	Dim oSheet As Sheet = oDoc.ActiveSheet
	
	Dim oTitleBlock As TitleBlock
		If oSheet.TitleBlock.Definition Is oTitleBlockDef1 Then

    	oSheet.TitleBlock.Delete()
	oTitleBlock = (oTitleBlockDef2)
		End If


	
	Else
	'mudar estilos para Alpha
	Dim oDoc1 As DrawingDocument
    oDoc1 = ThisApplication.ActiveDocument
	oDoc1.StylesManager.ActiveStandardStyle = oDoc1.StylesManager.StandardStyles("Alualpha")

End If

 

0 Likes
1,160 Views
4 Replies
Replies (4)
Message 2 of 5

wayne.brill
Collaborator
Collaborator

Hi,

 

Can you try using AddTitleBlock() of the Sheet? I did this quick test using part of your code and it is adding the title block. 

 

If oSheet.TitleBlock.Definition Is oTitleBlockDef1 Then

     oSheet.TitleBlock.Delete()  

     'oTitleBlock = (oTitleBlockDef2)'wB commented  

     oSheet.AddTitleBlock(oTitleBlockDef2) 'wB added  

End If

 

Sometimes it is helpful to test things in VBA. There is VBA sub in the help file that adds a title block. (InsertTitleBlockOnSheet). The Inventor API help is here on my system:

"C:\Program Files\Autodesk\Inventor 2014\Local Help\admapi_18_0.chm"

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 5

Anonymous
Not applicable

Sorry for my delay but or I dont know where exactly were to put it or it gives the message above.

 

Dim i As String
i = MessageBox.Show("Vai efectuar o desenho de uma ferramenta?", "ALUALPHA", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)

If i = "6" Then
		' mudar os estilos para ferramentas
	Dim oDoc As DrawingDocument
    oDoc = ThisApplication.ActiveDocument
	oDoc.StylesManager.ActiveStandardStyle = oDoc.StylesManager.StandardStyles("Alualpha Ferramentas")
	' defenir os title blocks
	Dim oTitleBlockDef1 As TitleBlockDefinition
	oTitleBlockDef1 = oDoc.TitleBlockDefinitions. _
    Item("Alualpha")
	Dim Val1 As Boolean = oTitleBlockDef1.IsReferenced
	
	Dim oTitleBlockDef2 As TitleBlockDefinition
	oTitleBlockDef2 = oDoc.TitleBlockDefinitions. _
    Item("Ferramentas")
	Dim Val2 As Boolean = oTitleBlockDef2.IsReferenced

	Dim oSheet As Sheet = oDoc.ActiveSheet
	
	Dim oTitleBlock As TitleBlock
		If oSheet.TitleBlock.Definition Is oTitleBlockDef1 Then

    	oSheet.TitleBlock.Delete()
	oTitleBlock = (oTitleBlockDef2)
		End If

If oSheet.TitleBlock.Definition Is oTitleBlockDef1 Then
 
     oSheet.TitleBlock.Delete()  
 
     'oTitleBlock = (oTitleBlockDef2)'wB commented  
 
     oSheet.AddTitleBlock(oTitleBlockDef2) 'wB added  
 
End If


	
	Else
	'mudar estilos para Alpha
	Dim oDoc1 As DrawingDocument
    oDoc1 = ThisApplication.ActiveDocument
	oDoc1.StylesManager.ActiveStandardStyle = oDoc1.StylesManager.StandardStyles("Alualpha")

End If

 

Capture.JPG

 

What I did wrong

TIA

FG

0 Likes
Message 4 of 5

wayne.brill
Collaborator
Collaborator

Hi,

 

Please attach your idw file with the rule. It will allow me to quickly recreate the error. 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 5

wayne.brill
Collaborator
Collaborator

Hi,

 

Thanks for emailing me the idw file. I was able to recreate the error. Those title blocks have prompt strings in them. You would need to provide these. When I tested this for my first reply I just had geometry in the TitleBlock. Here is an update:

 

Thanks,

Wayne

 

Dim i As String

i = MessageBox.Show("Vai efectuar o desenho de uma ferramenta?", "ALUALPHA", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)

 

If i = "6" Then

        ' mudar os estilos para ferramentas

    Dim oDoc As DrawingDocument

    oDoc = ThisApplication.ActiveDocument

    oDoc.StylesManager.ActiveStandardStyle = oDoc.StylesManager.StandardStyles("Alualpha Ferramentas")

   

    ' defenir os title blocks

    Dim oTitleBlockDef1 As TitleBlockDefinition

    oTitleBlockDef1 = oDoc.TitleBlockDefinitions. _

    Item("Alualpha")

    Dim Val1 As Boolean = oTitleBlockDef1.IsReferenced

   

    Dim oTitleBlockDef2 As TitleBlockDefinition

    oTitleBlockDef2 = oDoc.TitleBlockDefinitions. _

    Item("Ferramentas")

   

'    oTitleBlockDef2 = oDoc.TitleBlockDefinitions. _

'    Item("wBTest")

   

    Dim Val2 As Boolean = oTitleBlockDef2.IsReferenced

    Dim oSheet As Sheet = oDoc.ActiveSheet

 

    'wB commented

'    Dim oTitleBlock As TitleBlock

'    If oSheet.TitleBlock.Definition Is oTitleBlockDef1 Then

'

'        oSheet.TitleBlock.Delete()

'        oTitleBlock = (oTitleBlockDef2)

'    End If

 

If oSheet.TitleBlock.Definition Is oTitleBlockDef1 Then

 

     oSheet.TitleBlock.Delete() 

 

     'oTitleBlock = (oTitleBlockDef2)'wB commented 

    Dim sPromptStrings(0 To 9) As String

    sPromptStrings(0) = "String 1"

    sPromptStrings(1) = "String 2"

    sPromptStrings(2) = "String 2"

    sPromptStrings(3) = "String 2"

    sPromptStrings(4) = "String 2"

    sPromptStrings(5) = "String 2"

    sPromptStrings(6) = "String 2"

    sPromptStrings(7) = "String 2"

    sPromptStrings(8) = "String 2"

    sPromptStrings(9) = "String 2"

   

    MessageBox.Show("right before AddTitleBlock" + oTitleBlockDef2.Name )

    oSheet.AddTitleBlock(oTitleBlockDef2, , sPromptStrings) 'wB added 

 MessageBox.Show("right after AddTitleBlock")

End If

 

 

   

    Else

    'mudar estilos para Alpha

    Dim oDoc1 As DrawingDocument

    oDoc1 = ThisApplication.ActiveDocument

    oDoc1.StylesManager.ActiveStandardStyle = oDoc1.StylesManager.StandardStyles("Alualpha")

 

End If

 

'InventorVb.DocumentUpdate()

 

 

 

 

 

 

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network