Making my panel front plate faces front on base view

Making my panel front plate faces front on base view

bwangNYAKX
Contributor Contributor
810 Views
4 Replies
Message 1 of 5

Making my panel front plate faces front on base view

bwangNYAKX
Contributor
Contributor
Friends: thank you in advance.  When making drawings, the requirement for the model orientation is that: the base view has to show the dashboard of the panel (see attached image). i.e. the panel dash faces front within base view. I am wondering how I should do this through VBA.
 
My thought was to find the a plane parallel to panel dash and check its orientation and see if it is parallel to front view, right view or top view in TOP ASSEMBLY. (the dash will always be parallel to one of the three views) Right now, I got the XY plane of a panel subassembly called "xx screen" (variable "owp" in my code). The thing is that I don't know how to check the orientation of it. My owp.plane.normal=(0,0,1), but I believe this is in the local axis system of ("xx screen"). How can I check its orientation in terms of top assembly's XYZ?
 
 
 
  Sub Createdrawing()                   
    Dim oAssyDoc As AssemblyDocument
        Set oAssyDoc = ThisApplication.ActiveDocument
  
   Dim oPart As ComponentOccurrence
              For Each oPart In oAssyDoc.ComponentDefinition.Occurrences
            If (InStr(oPart.Name, "Control Panel") <> 0) And oPart.DefinitionDocumentType = kAssemblyDocumentObject Then
                     For Each oPart1 In oPart.Definition.Occurrences
                          If (InStr(oPart1.Name, "Door Assembly") <> 0) And oPart1.DefinitionDocumentType = kAssemblyDocumentObject Then
                                     For Each opart2 In oPart1.Definition.Occurrences
                                        If (InStr(opart2.Name, "Screen") <> 0) And opart2.Suppressed = False Then
                                        Dim owp As WorkPlane
                                        Set owp = opart2.Definition.WorkPlanes.Item("XY Plane")  ' Front Plane of Panel
                                        End If
                                        Next
                          End If
                    Next
           End If
            Next
 
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.Documents.Open("W:\AMICO SOURCE\AMICO SOURCE 3.0\Templates\AIR - 60Hz.dwg")
       Dim oSheet As Sheet
Set oSheet = oDoc.Sheets.Item(1)
    Dim oPoint1 As Point2d
Set oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(12.5, 16)  
 
Dim oView1 As DrawingView
Set oView1 = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint1, 0.1, kFrontViewOrientation, kShadedDrawingViewStyle)
...
end sub
       
0 Likes
Accepted solutions (1)
811 Views
4 Replies
Replies (4)
Message 2 of 5

Tony_Yates
Advocate
Advocate

Hi

 

We us this ilogic rule to set the front view before creating the drawing:-

 

Dim oCamera As Camera
oCamera = ThisApplication.ActiveView.Camera
oCamera.ViewOrientationType = 10764
oCamera.Apply


'  kDefaultViewOrientation = 10753
'  kTopViewOrientation = 10754
'  kRightViewOrientation = 10755
'  kBackViewOrientation = 10756
'  kBottomViewOrientation = 10757
'  kLeftViewOrientation = 10758
'  kIsoTopRightViewOrientation = 10759
'  kIsoTopLeftViewOrientation = 10760
'  kIsoBottomRightViewOrientation = 10761
'  kIsoBottomLeftViewOrientation = 10762
'  kArbitraryViewOrientation = 10763
'  kFrontViewOrientation = 10764
'  kCurrentViewOrientation = 10765
'  kSavedCameraViewOrientation = 10766
'  kFlatPivotRightViewOrientation = 10767
'  kFlatPivotLeftViewOrientation = 10768
'  kFlatPivot180ViewOrientation = 10769
'  kFlatBacksideViewOrientation = 10770
'  kFlatBacksidePivotRightViewOrientation = 10771
'  kFlatBacksidePivotLeftViewOrientation = 10772
'  kFlatBacksidePivot180ViewOrientation = 10773


Hope this helps. 

0 Likes
Message 3 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @bwangNYAKX 

To get the plane orientation in the context of the top level assembly, you'll have to create a geometry proxy for it, using it's containing occurrence. See code below 🙂

 

Sub Createdrawing()
Dim oAsm As AssemblyDocument
Set oAsm = ThisApplication.ActiveDocument
Dim oAsmDef As AssemblyComponentDefinition
Set oAsmDef = oAsm.ComponentDefinition
Dim oOcc As ComponentOccurrence
For Each oOcc In oAsmDef.Occurrences.AllLeafOccurrences
    If InStr(oOcc.Name, "UW Screen") Then Exit For
Next
Dim oWP As WorkPlane
Set oWP = oOcc.Definition.WorkPlanes.Item("XY Plane")
Dim oWPprox As WorkPlaneProxy
Call oOcc.CreateGeometryProxy(oWP, oWPprox)

Call ThisApplication.ActiveView.ResetFront
Dim oOrientation As ViewOrientationTypeEnum


If oWPprox.Plane.IsParallelTo(oAsmDef.WorkPlanes.Item("XY Plane").Plane) Then
    oOrientation = ViewOrientationTypeEnum.kFrontViewOrientation
    'MsgBox "Front"
ElseIf oWPprox.Plane.IsParallelTo(oAsmDef.WorkPlanes.Item("YZ Plane").Plane) Then
    oOrientation = ViewOrientationTypeEnum.kRightViewOrientation
    'MsgBox "Right"
ElseIf oWPprox.Plane.IsParallelTo(oAsmDef.WorkPlanes.Item("XZ Plane").Plane) Then
    oOrientation = ViewOrientationTypeEnum.kTopViewOrientation
    'MsgBox "Top"
Else
    MsgBox "Plane not parallel to any of Front, Right or Top"
    Exit Sub
End If



Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.Documents.Open("W:\AMICO SOURCE\AMICO SOURCE 3.0\Templates\AIR - 60Hz.dwg")
Dim oSheet As Sheet
Set oSheet = oDoc.Sheets.Item(1)
Dim oPoint1 As Point2d
Set oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(12.5, 16)
 
Dim oView1 As DrawingView
Set oView1 = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint1, 0.1, oOrientation, kShadedDrawingViewStyle)

End Sub
Message 4 of 5

bwangNYAKX
Contributor
Contributor

Thank you so much, my friend! This is exactly what I am looking for. Thanks for your time writing such a detailed script for me!!

0 Likes
Message 5 of 5

bwangNYAKX
Contributor
Contributor

Hi, you code works perfectly but when I try to implement it into my model, I don't know why the oWPprox.plane is still XY plane. The only difference is that my system doesn't have the "UW" directly under top assembly (see the screenshot below for CAD model tree) so I looped two times to get the UW Screen Occurrence.

 

The wired thing is that although I successfully got the UW Screen occurrence(store it in oOcc2 in my code) but Call oOcc2.CreateGeometryProxy(oWP, oWPprox) just gave me: oWPprox.plane.normal.z =1, x,y=0... On my model the screen is parallel to the right view, not front view. 

 

If you dont mind, could you have a quick look at my code and see what happened? I debugged it for an hour but had no any clue...

 

 

 

 

Dim oAsm As AssemblyDocument
Set oAsm = ThisApplication.ActiveDocument
Dim oAsmDef As AssemblyComponentDefinition
Set oAsmDef = oAsm.ComponentDefinition
Dim oOcc, oOcc1, oOcc2 As ComponentOccurrence
Dim oWP As WorkPlane
Dim oWPprox As WorkPlaneProxy
For Each oOcc In oAsmDef.Occurrences
    If InStr(oOcc.Name, "Control Panel") And oOcc.Suppressed = False Then
   
     For Each oOcc1 In oOcc.Definition.Occurrences
                                         If (InStr(oOcc1.Name, "Door Assembly") <> 0) And oOcc1.DefinitionDocumentType = kAssemblyDocumentObject And oOcc1.Suppressed = False Then
                                                    For Each oOcc2 In oOcc1.Definition.Occurrences
                                                       If (InStr(oOcc2.Name, "Screen") <> 0) And oOcc2.Suppressed = False Then
                                                   Set oWP = oOcc2.Definition.WorkPlanes.Item("XY Plane")
                                                   Call oOcc2.CreateGeometryProxy(oWP, oWPprox)
                                                   Exit For
                                                       End If
                                                    Next
                                         End If
    Next
    End If
Next
 
 
 

image.pngCapture.PNGCapture.PNG

0 Likes