Drawing View Label Position with iLogic

Drawing View Label Position with iLogic

ad64
Advocate Advocate
3,119 Views
2 Replies
Message 1 of 3

Drawing View Label Position with iLogic

ad64
Advocate
Advocate

How do I change the View Label position using iLogic? 

 

If I assign a point and try to sync the location, I get an error: [Error in Rule... Member not Found. (Exception from HRESULT: 0x800200003 (DISP_E_MEMBERNOTFOUND)]

 

SyntaxEditor Code Snippet

Dim wPoint As Point2d
    
For Each oView In oSheet.DrawingViews
    wPoint = ThisApplication.TransientGeometry.CreatePoint2d(oView.Position.X, oView.Position.Y)
    oView.Label.Position = wPoint 
Next

 

If I assign the X and Y individually, it doesn't appear to have any effect:

 

SyntaxEditor Code Snippet

    
For Each oView In oSheet.DrawingViews
    oView.Label.Position.X = oView.Position.X
Next

 

Any thoughts?

Steve

0 Likes
Accepted solutions (1)
3,120 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Accepted solution

 Hello Steve,

 

This should do the trick.

 

Regards Paul H.

 

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 oDrawDoc As DrawingDocument
    oDrawDoc = oApp.ActiveDocument

    ' Set a reference to the active sheet.
    Dim oActiveSheet As Sheet
    oActiveSheet = oDrawDoc.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 = oDrawDoc.SelectSet
    oSelectset.Clear()

    Dim oViews As DrawingViews = oActiveSheet.DrawingViews
    Dim oView As DrawingView = oActiveSheet.DrawingViews(1)

    For Each oView In oViews
        oSelectset.Select(oView)

'            MsgBox("VIEW LABEL POSITION X: " & oView.Label.Position.X & vbCrLf & _
'                   "VIEW LABEL POSITION Y: " & oView.Label.Position.Y, MsgBoxStyle.Information, _
'                   "DRAWING VIEW " & oView.Name & " LABEL POSITIONS")

        'Set reference oNewPosition as coordinate position
        Dim oNewPosition As Point2d
        oNewPosition = oView.Label.Position

        'Set reference to the new required position taken and create new 2d point
        oNewPosition = oTG.CreatePoint2d(oView.Center.X, oView.Center.Y - (oView.Height / 2) - 1)
		
        'Clear the selcted item
        oDrawDoc.SelectSet.Clear()

'        'Move Label Position to the new position (oNewPosition) 
        oView.Label.Position = oNewPosition
	
		oSelectset.Clear()
    Next
	
	
	
	End Sub
Message 3 of 3

cwhetten
Advisor
Advisor

I had the same issue as the OP.  The code in the marked solution has a lot of unnecessary stuff, but after boiling it down to the essentials, I found what actually makes that code work.  It boils down to a single line:

Dim oView As DrawingView = oActiveSheet.DrawingViews(1)

So, what it really comes down to is making sure Inventor knows the oView object is a DrawingView type.  With this in mind, the best way to fix the OP's code is to declare the type of the oView object when starting the for-each loop.  Basically, this simple addition to the OP's code is all that is needed:

Dim wPoint As Point2d
    
For Each oView As DrawingView In oSheet.DrawingViews
    wPoint = ThisApplication.TransientGeometry.CreatePoint2d(oView.Position.X, oView.Position.Y)
    oView.Label.Position = wPoint 
Next

 

Cameron Whetten
Inventor 2018
EE forum signature logo.png