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: 

Position View Label Below Dimensions

5 REPLIES 5
Reply
Message 1 of 6
donald_leigh
186 Views, 5 Replies

Position View Label Below Dimensions

Evening all

 

I have a rule that positions each view label at a set distance below each view. Is there a way to move the label based on the number of dimensions below the view. I found this rule a while ago (And cant find it again) and cant get it to work. Can anyone help me out please 

 

Donald

Inventor 2024

 

 

Sub Main

    Dim oDoc As DrawingDocument = ThisDoc.Document
    Dim oSheet As Sheet = oDoc.ActiveSheet
    Dim oView As DrawingView = oSheet.DrawingViews.Item(1) ' Assuming you're working with the first view

    ' Get the lowest Y position of all dimensions on the drawing sheet
    Dim lowestY As Double = GetLowestDimensionY(oSheet)

    ' Get the label associated with the view
    Dim oLabel As DrawingLabel = oView.Label

    ' Define the new position for the label
    Dim newX As Double = oLabel.Position.X
    Dim newY As Double = lowestY - 10 ' Adjust this value as needed for spacing

    ' Move the label to the new position
    oLabel.Move(New Point2d(newX, newY))

    ' Refresh the drawing to see the changes
    oSheet.Update()

End Sub

Function GetLowestDimensionY(sheet As Sheet) As Double
    Dim lowestY As Double = Double.MaxValue

    For Each oDim As GeneralDimension In Sheet.DrawingDimensions
        Dim dimPosition As Point2d = oDim.Position
        Dim dimY As Double = dimPosition.Y

        If dimY < lowestY Then
            lowestY = dimY
        End If
    Next

    Return lowestY
End Function

 

5 REPLIES 5
Message 2 of 6

Not tested!

Try to replace 

 

 

' Dim dimPosition As Point2d = oDim.Position
' Dim dimY As Double = dimPosition.Y
' with
Dim dimY As Double = oDim.Text.Origin.Y

 

 

Message 3 of 6
donald_leigh
in reply to: donald_leigh

The error I'm getting is:

Error on Line 11 : Type 'DrawingLabel' is not defined.
Error on Line 19 : 'New' cannot be used on an interface.

 

Donald 

Message 4 of 6

@donald_leigh 

 

See example, and updates in blue.

 

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

 

Sub Main

    Dim oDoc As DrawingDocument = ThisDoc.Document
    Dim oSheet As Sheet = oDoc.ActiveSheet
    Dim oView As DrawingView = oSheet.DrawingViews.Item(1) ' Assuming you're working with the first view

    ' Get the lowest Y position of all dimensions on the drawing sheet
    Dim lowestY As Double = GetLowestDimensionY(oSheet)

    ' Get the label associated with the view
    Dim oLabel As DrawingViewLabel = oView.Label

    ' Define the new position for the label
    Dim newX As Double = oLabel.Position.X
    Dim newY As Double = lowestY - 1 ' Adjust this value as needed for spacing
	
	Dim oPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(newX, newY)

    ' Move the label to the new position
    oLabel.Position = oPoint

    ' Refresh the drawing to see the changes
    oSheet.Update()

End Sub

Function GetLowestDimensionY(sheet As Sheet) As Double
    Dim lowestY As Double = Double.MaxValue

    For Each oDim As GeneralDimension In sheet.DrawingDimensions
        Dim dimPosition As Point2d = oDim.Text.Origin
        Dim dimY As Double = dimPosition.Y

        If dimY < lowestY Then
            lowestY = dimY
        End If
    Next

    Return lowestY
End Function

 

Message 5 of 6
donald_leigh
in reply to: donald_leigh

Thanks @Curtis_Waguespack that is just what  was looking for.

Message 6 of 6
donald_leigh
in reply to: donald_leigh

Hi Again @Curtis_Waguespack 

 

The rule you amended above will move the view label of the 1st base view only a set distance below the lowest dimension on the whole drawing. if there is another view, with dimensions (In the Y direction), that is lower then the base view the label of the base view will move below tat other view.

 

I have changed the rule (See below) to move all the view labels but its moving them all based on the rule dim above and places them in line with each other.

 

What I would like is the rule above to run on only 1 view at a time, and move the view label based on that view only.

 

i hope this is making sense?

 

new rule:

 
Public Sub Main
	Call RepositionDrawingViewLabels
End Sub

Private Sub RepositionDrawingViewLabels()
	'Set a reference to the drawing document.
	'This assumes a drawing document is active.
	Dim oApp = ThisApplication
	Dim oDoc As DrawingDocument
	oDoc = oApp.ActiveDocument
	
	'Set a reference to the active sheet.
	Dim oActiveSheet As Sheet
	oActiveSheet = oDoc.ActiveSheet
	
	'Set a reference to the TransientGeometry on active sheet.
	Dim oTG As TransientGeometry
	oTG = oApp.TransientGeometry
	
	'This Drawing Document Select Set
	Dim oSelectset As SelectSet = oDoc.SelectSet
	oSelectset.Clear()
	
	Dim oSheet As Sheet = oDoc.ActiveSheet
	Dim oViews As DrawingViews = oActiveSheet.DrawingViews
	Dim oView As DrawingView = oSheet.DrawingViews.Item(1) ' Assuming you're working with the first view
	
	For Each oView In oViews
		oSelectset.Select(oView)
		
		'Get the lowest Y position of all dimensions on the drawing sheet
		Dim lowestY As Double = GetLowestDimensionY(oSheet)
		
		'Get the label associated with the view
		Dim oLabel As DrawingViewLabel = oView.Label
		
		'Define the new position for the label
		Dim newX As Double = oLabel.Position.X
		Dim newY As Double = lowestY - 1 ' Adjust this value as needed for spacing
		
		Dim oPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(newX, newY)
		
		'Move the label to the new position
		oLabel.Position = oPoint
		
		'Refresh the drawing to see the changes
		oSheet.Update()
	Next
	iLogicVb.UpdateWhenDone = True
End Sub

Function GetLowestDimensionY(sheet As Sheet) As Double
	Dim lowestY As Double = Double.MaxValue
	For Each oDim As GeneralDimension In sheet.DrawingDimensions
		Dim dimPosition As Point2d = oDim.Text.Origin
		Dim dimY As Double = dimPosition.Y
	
		If dimY < lowestY Then
			lowestY = dimY
		End If
	Next

	Return lowestY
End Function

 

Donald

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report