View from 3D vba macro

Tadej Znideric

View from 3D vba macro

Hello,

does anyone know how to program a code View from 3D in VBA for CATIA drawing? I would like to create a drawing automaticly with views by choosing an option View from 3D.

 

For all other options Front view, Isometric view etc is it possible to create a vba code by recording, but when I try View from 3D I can not get any code.

 

I appreciate for any help,

Thanks

 

Harshal Trivedi, Senior PLM Consultant

RE: View from 3D vba macro
(in response to Tadej Znideric)

Hi Tadej

You can use method DefineIsometricView in you macro where you generate new view.

e.g.---

' Create a view called "3D Iso View" in this sheet
Dim oIsoView As DrawingView
Set oISoView = oSheet.Views.Add("3D View")

    ' Retrieve it generative behavior
Dim oISoViewGB As DrawingViewGenerativeBehavior
Set oISoViewGB = oISoView.GenerativeBehavior ' Declare the part to draw in this view
    oISoViewGB.Document = oPartToDraw

    ' Define this view as a view, with the XY plane (in oPartToDraw) as projection plane
    oISoViewGB.DefineIsometricView -0.707, 0.707, 0., 0., 0., 1.

' Position the View in the Sheet
   oISoView.x = 300
   oISoView.y = 150

    ' Update the view
   oISoViewGB.Update

-----
Hope this helps.

Regards

Harshal Trivedi

Senior PLM Consultant

TATA Technologies

United Kingdom

Roland Friedrich

RE: View from 3D vba macro
(in response to Harshal Trivedi, Senior PLM Consultant)

first retrieve the view direction of the 3D window using GetSightDirection and GetUpDirection then use these values for DefineIsometricView

you might have to do some vector calculation for this to work, not sure anymore, but I did this before


Regards,
Roland

Edited By:
Roland Friedrich[PDTec] @ May 18, 2016 - 01:09 PM (Europe/Berlin)

Tadej Znideric

RE: View from 3D vba macro
(in response to Harshal Trivedi, Senior PLM Consultant)

Thank you for code Mr. Harshal,

Do you have any suggestion to define a View from 3D option in VBA? Please see code and an icion in attachment which I want to define (View_from_3d.jpg). Thanks.

 

 

Sub CATMain()

Dim windows1 As Windows
Set windows1 = CATIA.Windows

Dim specsAndGeomWindow1 As SpecsAndGeomWindow
Set specsAndGeomWindow1 = windows1.Item("Part_name.CATPart")

specsAndGeomWindow1.Activate

Dim specsAndGeomWindow2 As SpecsAndGeomWindow
Set specsAndGeomWindow2 = windows1.Item("Drawing1")

specsAndGeomWindow2.Activate

Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument

Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets

Dim oSheet As DrawingSheet
Set oSheet = drawingSheets1.ActiveSheet

specsAndGeomWindow1.Activate

 

Dim oIsoView As DrawingView
Set oIsoView = oSheet.Views.Add("View from 3D")

specsAndGeomWindow2.Activate


Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim partDocument1 As PartDocument
Set partDocument1 = documents1.Item("Part_name.CATPart")

Dim product1 As Product
Set product1 = partDocument1.GetItem("Part_name")

Dim oIsoViewGB As DrawingViewGenerativeBehavior
Set oIsoViewGB = oIsoView.GenerativeBehavior

 

oIsoViewGB.Document = product1

oIsoViewGB.DefineIsometricView 1#, 0#, 0#, 0#, 1#, 0#   ' here I want to define a View from 3D option

oIsoView.X = 300
  oIsoView.Y = 150

   oIsoViewGB.Update

End Sub

Attachments

  • View_from_3d.jpg (8.1k)

LEE KING

RE: View from 3D vba macro
(in response to Tadej Znideric)

Hi, Tadej;

Did you solve this problem? 

Could you share the mothed;

thanks