Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Automatic Drawing View Label Doesnt Work If View Is At an Angle

C_Haines_ENG
Collaborator

Automatic Drawing View Label Doesnt Work If View Is At an Angle

C_Haines_ENG
Collaborator
Collaborator

I currently have this code to automatically name drawing views, however this only works if the viewcube is in the exact orientation with no rotation.

 

'[ SETUP BLOCK
Dim tmpSheet As Sheet = ThisDrawing.ActiveSheet.Sheet 'Set active sheet for local iLogic rule existing inside Drawing document
Dim oView As DrawingView = tmpSheet.DrawingViews.Item(1) 'Get 1st view to determin base output
Dim oRDD As DocumentDescriptor = oView.ReferencedDocumentDescriptor
Dim oModelType As String

']

'[ VIEW LOOP
For Each tmpView As DrawingView In tmpSheet.DrawingViews
	Dim myDrawingViewName As String = ""
	'Check name. anything NOT matching the master list or the name is NOT numbers only will get skipped
	If Not masterList.Contains(tmpView.Name) And Not IsNumeric(tmpView.Name) Then Continue For
	
	Dim oTrans As Transaction
	oTrans = ThisApplication.TransactionManager.StartTransaction(ThisDrawing.Document, "Rotate Drawing View temp")
	
		' Set rotation to 0
	If tmpView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kArbitraryViewOrientation Then
		If tmpView.Rotation <> 0 Then
			tmpView.Rotation = 0
		End If
	End If	
']

'[ CASE SELECTOR

'[ PART VIEW LABELS
    Select Case tmpView.Camera.ViewOrientationType
        Case ViewOrientationTypeEnum.kBackViewOrientation
            myDrawingViewName = "O/S FACE"
        Case ViewOrientationTypeEnum.kBottomViewOrientation
            myDrawingViewName = "BOTTOM"
        Case ViewOrientationTypeEnum.kFrontViewOrientation
            myDrawingViewName = "I/S FACE"
        Case ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation
            myDrawingViewName = ""
        Case ViewOrientationTypeEnum.kIsoBottomRightViewOrientation
            myDrawingViewName = ""
        Case ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
            myDrawingViewName = ""
        Case ViewOrientationTypeEnum.kIsoTopRightViewOrientation
            myDrawingViewName = ""
        Case ViewOrientationTypeEnum.kLeftViewOrientation
            myDrawingViewName = "END"
        Case ViewOrientationTypeEnum.kRightViewOrientation
            myDrawingViewName = "END"
        Case ViewOrientationTypeEnum.kTopViewOrientation
            myDrawingViewName = "TOP"
        Case Else
            myDrawingViewName = ""
    End Select
    If Not myDrawingViewName = "" Then
        tmpView.Name = myDrawingViewName
    End If
End If

'Always close your Transactions
oTrans.End

Next
  

 I cant find the original post where this code was given, however the addition near the top of

 

		' Set rotation to 0
	If tmpView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kArbitraryViewOrientation Then
		If tmpView.Rotation <> 0 Then
			tmpView.Rotation = 0
		End If
	End If	

 

 

Was supposed to resolve the problem. It did not. 

 

Does anyone know how to fix this bug? Ive checked what I can and the view sends back that its at 0 degrees no matter what so I guess that didnt fix it at all.

 

Ive decided to add more context here. If a drawing view is orented like this:

 

chainesL5H3G_1-1675976290594.png

 

It works fine. However if the view is oriented as such:

 

chainesL5H3G_2-1675976321981.png

It doesnt work, I understand this is because ViewOrientationTypeEnum.kTopViewOrientation is technically not true due to this however that is remarkably dumb....

 

 

0 Likes
Reply
336 Views
6 Replies
Replies (6)

dalton98
Collaborator
Collaborator

Use pi / 2 instead of 0. Then change it back after you set the name.

Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oView As DrawingView = oDDoc.ActiveSheet.DrawingViews(1)
MessageBox.Show(oView.Camera.ViewOrientationType.ToString)
origionalRotation = oView.Rotation
oView.Rotation = PI / 2
myDrawingViewName = oView.Camera.ViewOrientationType.ToString
oView.Rotation = origionalRotation
MessageBox.Show(myDrawingViewName)
0 Likes

C_Haines_ENG
Collaborator
Collaborator

This sadly doesnt work, It stays as an "arbitrary view"

0 Likes

dalton98
Collaborator
Collaborator

Can you post ur code? It works for me.

0 Likes

C_Haines_ENG
Collaborator
Collaborator
'[ SETUP BLOCK
Dim tmpSheet As Sheet = ThisDrawing.ActiveSheet.Sheet 'Set active sheet for local iLogic rule existing inside Drawing document
Dim oView As DrawingView = tmpSheet.DrawingViews.Item(1) 'Get 1st view to determin base output
Dim oRDD As DocumentDescriptor = oView.ReferencedDocumentDescriptor
Dim oModelType As String
'Set list for names you want to identify. Anything matching these names will be updated
Dim masterList As New List(Of String)
masterList.AddRange({"BACK", "BOTTOM", "FRONT", "SIDE", "TOP", "O/S FACE", "I/S FACE", "END"})

']

'[ VIEW LOOP
For Each tmpView As DrawingView In tmpSheet.DrawingViews
	Dim myDrawingViewName As String = ""
	'Check name. anything NOT matching the master list or the name is NOT numbers only will get skipped
	If Not masterList.Contains(tmpView.Name) And Not IsNumeric(tmpView.Name) Then Continue For
	
	Dim oTrans As Transaction
	oTrans = ThisApplication.TransactionManager.StartTransaction(ThisDrawing.Document, "Rotate Drawing View temp")
	
		' Set rotation to 0
	If tmpView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kArbitraryViewOrientation Then
		origionalRotation = tmpView.Rotation
			tmpView.Rotation = PI / 2
	End If	
']

'[ CASE SELECTOR
	'[ PART VIEW LABELS
If Parameter("DrawingType") <> "Part"


    Select Case tmpView.Camera.ViewOrientationType
        Case ViewOrientationTypeEnum.kBackViewOrientation
            myDrawingViewName = "BACK"
        Case ViewOrientationTypeEnum.kBottomViewOrientation
            myDrawingViewName = "BOTTOM"
        Case ViewOrientationTypeEnum.kFrontViewOrientation
            myDrawingViewName = "FRONT"
        Case ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation
            myDrawingViewName = "ISOMETRIC"
        Case ViewOrientationTypeEnum.kIsoBottomRightViewOrientation
            myDrawingViewName = "ISOMETRIC"
        Case ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
            myDrawingViewName = "ISOMETRIC"
        Case ViewOrientationTypeEnum.kIsoTopRightViewOrientation
            myDrawingViewName = "ISOMETRIC"
        Case ViewOrientationTypeEnum.kLeftViewOrientation
            myDrawingViewName = "SIDE"
        Case ViewOrientationTypeEnum.kRightViewOrientation
            myDrawingViewName = "SIDE"
        Case ViewOrientationTypeEnum.kTopViewOrientation
            myDrawingViewName = "TOP"
        Case Else
            myDrawingViewName = ""
    End Select
    If Not myDrawingViewName = "" Then
        tmpView.Name = myDrawingViewName
    End If

    myDrawingViewName = ""


']

'[ PART VIEW LABELS
Else

    Select Case tmpView.Camera.ViewOrientationType
        Case ViewOrientationTypeEnum.kBackViewOrientation
            myDrawingViewName = "O/S FACE"
        Case ViewOrientationTypeEnum.kBottomViewOrientation
            myDrawingViewName = "BOTTOM"
        Case ViewOrientationTypeEnum.kFrontViewOrientation
            myDrawingViewName = "I/S FACE"
        Case ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation
            myDrawingViewName = ""
        Case ViewOrientationTypeEnum.kIsoBottomRightViewOrientation
            myDrawingViewName = ""
        Case ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
            myDrawingViewName = ""
        Case ViewOrientationTypeEnum.kIsoTopRightViewOrientation
            myDrawingViewName = ""
        Case ViewOrientationTypeEnum.kLeftViewOrientation
            myDrawingViewName = "END"
        Case ViewOrientationTypeEnum.kRightViewOrientation
            myDrawingViewName = "END"
        Case ViewOrientationTypeEnum.kTopViewOrientation
            myDrawingViewName = "TOP"
        Case Else
			MessageBox.Show(tmpView.Rotation, "Title")

            myDrawingViewName = ""
    End Select
    If Not myDrawingViewName = "" Then
        tmpView.Name = myDrawingViewName
    End If
End If

tmpView.Rotation = origionalRotation

'Always close your Transactions
oTrans.End


Next
0 Likes

dalton98
Collaborator
Collaborator

Ohh ok this is odd. The view.Rotation (original rotation) seems to always be 0. Not the true rotation based off the cube. I got it to work by running the rule twice. 1st time setting the rotation = pi / 2. 2nd time setting the rotation = pi. Depending on the way the view was originally rotated.

 

It can be setup something like this:

myDrawingViewName = ""

origionalRotation = tmpView.Rotation
tmpView.Rotation = PI

Select Case tmpView.Camera.ViewOrientationType
	Case ViewOrientationTypeEnum.kBackViewOrientation
		myDrawingViewName = "BACK"
	Case Else
		myDrawingViewName = ""
End Select

tmpView.Rotation = PI / 2

Select Case tmpView.Camera.ViewOrientationType
	Case ViewOrientationTypeEnum.kBackViewOrientation
		myDrawingViewName = "BACK"
	Case Else
		'nothing
End Select

tmpView.Rotation = origionalRotation

 Also on line 61 you are setting the value back to " ".

0 Likes

dalton98
Collaborator
Collaborator

I wrote this. It uses a function to determine the drawingViewName. It makes it cleaner imo.

Sub Main
	'[ SETUP BLOCK
	Dim tmpSheet As Sheet = ThisDrawing.ActiveSheet.Sheet 'Set active sheet for local iLogic rule existing inside Drawing document
	Dim oView As DrawingView = tmpSheet.DrawingViews.Item(1) 'Get 1st view to determin base output
	Dim oRDD As DocumentDescriptor = oView.ReferencedDocumentDescriptor
	Dim oModelType As String
	'Set list for names you want to identify. Anything matching these names will be updated
	Dim masterList As New List(Of String)
	masterList.AddRange({"BACK", "BOTTOM", "FRONT", "SIDE", "TOP", "O/S FACE", "I/S FACE", "END" })

	']

	'[ VIEW LOOP
	For Each tmpView As DrawingView In tmpSheet.DrawingViews
		Dim myDrawingViewName As String = ""
		'Check name. anything NOT matching the master list or the name is NOT numbers only will get skipped
		'	If Not masterList.Contains(tmpView.Name) Then Continue For

		'	Dim oTrans As Transaction
		'	oTrans = ThisApplication.TransactionManager.StartTransaction(ThisDrawing.Document, "Rotate Drawing View temp")

		myDrawingViewName = ""
		origionalRotation = tmpView.Rotation
		
		If tmpView.Camera.ViewOrientationType <> ViewOrientationTypeEnum.kArbitraryViewOrientation Then
			myDrawingViewName = NotPartViewLabels(tmpView)
		Else
			tmpView.Rotation = PI
			myDrawingViewName = NotPartViewLabels(tmpView)
			If myDrawingViewName = ""
				tmpView.Rotation = PI / 2
				myDrawingViewName = NotPartViewLabels(tmpView)
			End If
		End If
		
		tmpView.Rotation = origionalRotation
		tmpView.Name = myDrawingViewName
		
	Next
	']

End Sub

Function NotPartViewLabels(tmpView As DrawingView)
	'[ PART VIEW LABELS
If Parameter("DrawingType") <> "Part"

    Select Case tmpView.Camera.ViewOrientationType
        Case ViewOrientationTypeEnum.kBackViewOrientation
            myDrawingViewName = "BACK"
        Case ViewOrientationTypeEnum.kBottomViewOrientation
            myDrawingViewName = "BOTTOM"
        Case ViewOrientationTypeEnum.kFrontViewOrientation
            myDrawingViewName = "FRONT"
        Case ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation
            myDrawingViewName = "ISOMETRIC"
        Case ViewOrientationTypeEnum.kIsoBottomRightViewOrientation
            myDrawingViewName = "ISOMETRIC"
        Case ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
            myDrawingViewName = "ISOMETRIC"
        Case ViewOrientationTypeEnum.kIsoTopRightViewOrientation
            myDrawingViewName = "ISOMETRIC"
        Case ViewOrientationTypeEnum.kLeftViewOrientation
            myDrawingViewName = "SIDE"
        Case ViewOrientationTypeEnum.kRightViewOrientation
            myDrawingViewName = "SIDE"
        Case ViewOrientationTypeEnum.kTopViewOrientation
            myDrawingViewName = "TOP"
        Case Else
            myDrawingViewName = ""
    End Select

End If

']

Return myDrawingViewName

End Function 

 

0 Likes