Referencing specific dimensions in titleblocks

Referencing specific dimensions in titleblocks

Anonymous
Not applicable
481 Views
2 Replies
Message 1 of 3

Referencing specific dimensions in titleblocks

Anonymous
Not applicable

I've been working working with Curtis on a project involving editing dimensions of titleblocks using iLogic/VBA:

 

https://forums.autodesk.com/t5/inventor-general-discussion/passing-ilogic-parameter-into-dimension-v...

 

Currently the code is like this:

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oTitleBlockDef As TitleBlockDefinition
oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item("A-B")

Dim oSketch As DrawingSketch
oTitleBlockDef.Edit(oSketch)

Dim oDim As DimensionConstraint

For Each oDim In oSketch.DimensionConstraints
            If oDim.Parameter.Name = "d0" Then
            Exit For
        End If
Next

Select Case HeightCheck
    Case ActiveSheet.Height = 11 
        oDim.Parameter.Value = (8.5 - 0.25  - 0.25  - 0.75 - (0.25*5)) * 2.54
        
        ThisApplication.ActiveDocument.Update
    Case ActiveSheet.Height = 17 
        oDim.Parameter.Value = (11 - 0.25 - 0.25 - 0.75 - (0.25 * 5)) * 2.54
        
        ThisApplication.ActiveDocument.Update
End Select

oTitleBlockDef.ExitEdit(True)

Where there's a for loop to search for a dimension labeled "d0", and then modifies it.

 

The problem is that I have to execute the rule *twice* for it to actually adjust to the sheet, which tells me that there's some kind of indexing problem or return value of the for loop, or something to that effect.

 

Is there a way to reference the 'd0' dimension explicitly by name and modify it without having to search for it?

 

 

0 Likes
482 Views
2 Replies
Replies (2)
Message 2 of 3

rossano_praderi
Collaborator
Collaborator

Hi,

no is not possible.

 

This is your code with some modifications.

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oTitleBlockDef As TitleBlockDefinition
i=0
Do
	i=i+1
	If oDrawDoc.TitleBlockDefinitions.Item(i).Name = "A-B"
		oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item(i)
	End If
Loop Until oDrawDoc.TitleBlockDefinitions.Item(i).Name = "A-B" Or i = oDrawDoc.TitleBlockDefinitions.count

Dim oSketch As DrawingSketch
oTitleBlockDef.Edit(oSketch)

Dim oDim As DimensionConstraint
i=0
Do
	i=i+1
	oDim = oSketch.DimensionConstraints.item(i)
	If oDim.Parameter.Name = "d0" Then
		Select Case ActiveSheet.Height
			Case 11 
				oDim.Parameter.Value = (8.5 - 0.25  - 0.25  - 0.75 - (0.25*5)) * 2.54
				ThisApplication.ActiveDocument.Update
			Case 17 
				oDim.Parameter.Value = (11 - 0.25 - 0.25 - 0.75 - (0.25 * 5)) * 2.54
				ThisApplication.ActiveDocument.Update
		End Select
    End If
Loop Until oDim.Parameter.Name = "d0" Or i=oSketch.DimensionConstraints.count
			
oTitleBlockDef.ExitEdit(True)

May be this isn't the best solution, but work well.

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
0 Likes
Message 3 of 3

wayne.brill
Collaborator
Collaborator

Hi Robert,

 

Not sure if it makes sense for what you are doing but you could add an attribute to the DimensionConstraint. (This DevBlog post discussess attributes)

http://adndevblog.typepad.com/manufacturing/2013/03/save-extra-data-in-inventor-file-2.html

 

Thanks,

Wayne

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network