Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to create an Isometric View on a CATDrawing 2

Status
Not open for further replies.

hcavalini

Mechanical
Jan 12, 2016
4
DE
Greetings,​
this is my first post on this forum so excuse my poor English and any mistake.

Long story short, I am writing a code that creates an Isometric View from a CATPart on a CATDrawing and I am facing two three problems:
[ol 1]
[li]The DefineIsometricView method need six parameters to be defined: iX1, iY1, iZ1, iX2, iY2 and iZ2. I was able to retrieve iX2, iY2 and iZ2 using the GetUpDirection method of a Viewpoint3D object but I can't find a way to retrieve the first vector components (iX1, iY1 and iZ1).[/li]
[li]After the creation of the Isometric View the macro need to change its properties. I can change almost all of them except for the view generation mode that has to be changed from "Exact" to "Raster" with the Raster Mode being changed to Shading. This image explains what I want the macro to do: Image. I can't change the 3D Wireframe option from "Can be hidden" to "Is always visible" either.[/li]
[li]EDIT: I just noticed another issue. I ran the macro on my computer and it worked "fine" the first time. The second time I couldn't select the "Join surface" (HybridShapeAssemble) and the macro freezes, I had to restart CATIA. any idea why this is happening, or how can I fix it? [/li]
[/ol]

I searched the internet and the V5 Automation help file but I couldn't find anything.Actually, after reading the properties from the DrawingView object in the V5 Automation file, I don't know if it is even possible to do what I need on Item 2.

This is the code I am currently working on:

Code:
Sub CATMain()

Dim Drawing1 As DrawingDocument
Set Drawing1 = CATIA.ActiveDocument

MsgBox ("Please select now the CATPart File")

Dim FilePath1 As String
FilePath1 = CATIA.FileSelectionBox("Select the CATPart File", "*.CATPart", 0)
If FilePath1 = "" Then Exit Sub

Dim Part1 As PartDocument
Set Part1 = CATIA.Documents.Open(FilePath1)

Set UserSel = Part1.Selection
UserSel.Clear

Dim varFilter(0) As Variant
varFilter(0) = "HybridShapeAssemble"

Dim Join1
Join1 = UserSel.SelectElement2(varFilter, MsgBox("Please select now the Join surface"), False)

Dim specsAndGeomWindow1 As SpecsAndGeomWindow
Set specsAndGeomWindow1 = CATIA.ActiveWindow

Dim viewer3D1 As Viewer3D
Set viewer3D1 = specsAndGeomWindow1.ActiveViewer

Dim viewpoint3D1
Set viewpoint3D1 = viewer3D1.Viewpoint3D

Dim Up(2)

viewpoint3D1.GetUpDirection Up

UserSel.Clear

Drawing1.Activate

Dim Sheet1 As DrawingSheet
Set Sheet1 = Drawing1.Sheets.ActiveSheet

Dim IsoView1 As DrawingView
Set IsoView1 = Sheet1.Views.Add("Isometric View")

Dim IsoView1GB As DrawingViewGenerativeBehavior
Set IsoView1GB = IsoView1.GenerativeBehavior

IsoView1GB.Document = Part1

IsoView1GB.DefineIsometricView 1, 1, 0, Up(0), Up(1), Up(2)

IsoView1.X = 172.5
IsoView1.Y = 150
IsoView1.[Scale] = 1 / 5
IsoView1GB.ColorInheritanceMode = cat3DColorInheritanceModeOn
    
IsoView1GB.Update

IsoView1.Activate

Dim Sel1 As Selection
Set Sel1 = Drawing1.Selection
Sel1.Search "(Name=Text.1),all"

Dim visProperties1 As VisPropertySet
Set visProperties1 = Sel1.VisProperties
visProperties1.SetShow catVisPropertyNoShowAttr

Sel1.Clear

Sel1.Search "(Name=Origin),all"
visProperties1.SetShow catVisPropertyNoShowAttr

Sel1.Clear

Sel1.Search "(Name=HDirection),all"
visProperties1.SetShow catVisPropertyNoShowAttr

Sel1.Clear

Sel1.Search "(Name=VDirection),all"
visProperties1.SetShow catVisPropertyNoShowAttr

Sel1.Clear

End Sub

Any help would be highly appreciated.

Regards,
Hugo.
 
Replies continue below

Recommended for you

Hi

Can you upload a sample part? What release do you run?

In on line docs I can see (v5automation.chm for r25):
--------------------------------------------
o Property ImageViewMode( ) As CatImageViewMode
Returns or sets the view generation mode as pixel image.
Returns:
S_OK
if the operation succeeded.
E_FAIL
For both methods, if an unspecified failure has occurred
Example:
This example sets the view image generation mode of the MyView
drawing view to catImageModeHRD to indicate that view is generated as an
HRD image.
MyView.GenerativeBehavior.CatImageViewMode(catImageModeHRD)
--------------------------------------------
CatImageViewMode (Enumeration)
enum CatImageViewMode {
catImageModeOff,
catImageModeHRD
}
Image view mode.
Values:
catImageModeOff
No image is generated. (Standard 2D geometry is created)
catImageModeHRD
The view is generated as a pixel image in HRD mode
----------------------------------------------



Regards
Fernando

- Romania
- EU
 
Hello,​
thanks for the answer Ferdo, the sample part is attached to this reply and I am using the release 2014, Service Pack 4 Build Number 24.

I had no idea that the HRD mode was the "Raster mode" thanks for pointing that out.

By the way, the example of the CATIA help file is wrong (At least for the release I am using).

Instead of
Code:
MyView.GenerativeBehavior.CatImageViewMode (catImageModeHDR)
it is
Code:
MyView.GenerativeBehavior.ImageViewMode = catImageModeHDR

Your answer solves half of the 2nd point. Do you know how can I change the Raster mode to Shading? (Like in the Image I posted)


 
 http://files.engineering.com/getfile.aspx?folder=ee4b451d-0137-472c-b060-427421349df2&file=FORUM_SAMPLE_-_Kopie.CATPart
Maybe this will help you a little bit more


RasterLevelOfDetail (Enumeration)
enum RasterLevelOfDetail {
LowQuality,
NormalQuality,
HighQuality,
Customize
}

Precision for views generated as raster (DPI).

Values:
NormalQuality
With this precision, an edge from raster view will have the correct width for print purpose.
LowQuality
This precision is 4 times smaller than NormalQuality
HighQuality
This precision is 4 times bigger than NormalQuality
Customize
Whenever you want to define the value (DPI)


Regards
Fernando

- Romania
- EU
 
Unfortunately it didn't. I couldn't use the RasterLevelOfDetail as a method, but I don't need to change the quality of the Raster just the mode so it wouldn't change my situation anyways. Thank you for the information though!

I was able to solve the problem of point 3. I still don't know what exactly triggered the problem, but I was able to solve it and now the code works fine (with exception of point 1 and 2 problems). I updated the code to the actual version.

ferdo, you have no idea how can I calculate V1 coordinates? I don't know if i made myself clear enough so I will try to explain it with an example:

When you record a macro to create an isometric view, CATIA calculates the vectors of what you're current seeing at your screen. So when you look at the code you've recorded you have the coordinates of V1 and V2 that CATIA calculated from whatever was your viewpoint. I know how to calculate V2 for whatever viewpoint is my current because the coordinates of V2 of your actual viewpoint can be retrieved using the GetUpDirection method, but I can't retrieve the V1 coordinates and I need them because the user will manually position the Part before the DefineIsometicView method is executed, so I can't simply use "static" values for V1 because they will have to change every time the user changes the viewpoint.

I hope you could understand what I am talking about.

EDIT: Since I couldn't edit my previous post here goes the actual code:

Code:
Sub CATMain()

Dim Drawing1 As DrawingDocument
Set Drawing1 = CATIA.ActiveDocument

MsgBox ("Please select now the CATPart File")

Dim FilePath1 As String
FilePath1 = CATIA.FileSelectionBox("Select the CATPart File", "*.CATPart", 0)
If FilePath1 = "" Then Exit Sub

For I = 1 To CATIA.Documents.Count

If FilePath1 = CATIA.Documents.Item(I).FullName Then GoTo Jump

Next

CATIA.Documents.Open (FilePath1)

Jump:
CATIA.Documents.Item(I).Activate

Dim Part1 As PartDocument
Set Part1 = CATIA.ActiveDocument

Set UserSel = Part1.Selection
UserSel.Clear

Dim varFilter(0) As Variant
varFilter(0) = "HybridShapeAssemble"

Dim Join1
Join1 = UserSel.SelectElement2(varFilter, MsgBox("Please select now the Join surface"), False)

If Join1 <> "Normal" Then Exit Sub

Dim specsAndGeomWindow1 As SpecsAndGeomWindow
Set specsAndGeomWindow1 = CATIA.ActiveWindow

Dim viewer3D1 As Viewer3D
Set viewer3D1 = specsAndGeomWindow1.ActiveViewer

Dim viewpoint3D1
Set viewpoint3D1 = viewer3D1.Viewpoint3D

Dim Up(2)

viewpoint3D1.GetUpDirection Up

UserSel.Clear

Drawing1.Activate

Dim Sheet1 As DrawingSheet
Set Sheet1 = Drawing1.Sheets.ActiveSheet

Dim IsoView1 As DrawingView
Set IsoView1 = Sheet1.Views.Add("Isometric View")

Dim IsoView1GB As DrawingViewGenerativeBehavior
Set IsoView1GB = IsoView1.GenerativeBehavior

IsoView1GB.Document = Part1

IsoView1GB.DefineIsometricView 1, 1, 0, Up(0), Up(1), Up(2)

IsoView1.X = 172.5
IsoView1.Y = 150
IsoView1.[Scale] = 1 / 5
IsoView1GB.ColorInheritanceMode = cat3DColorInheritanceModeOn
IsoView1GB.ImageViewMode = catImageModeHRD
    
IsoView1GB.Update

IsoView1.Activate

Dim Sel1 As Selection
Set Sel1 = Drawing1.Selection
Sel1.Search "(Name=Text.1),all"

Dim visProperties1 As VisPropertySet
Set visProperties1 = Sel1.VisProperties
visProperties1.SetShow catVisPropertyNoShowAttr

Sel1.Clear

Sel1.Search "(Name=Origin),all"
visProperties1.SetShow catVisPropertyNoShowAttr

Sel1.Clear

Sel1.Search "(Name=HDirection),all"
visProperties1.SetShow catVisPropertyNoShowAttr

Sel1.Clear

Sel1.Search "(Name=VDirection),all"
visProperties1.SetShow catVisPropertyNoShowAttr

Sel1.Clear

End Sub

 
Hi,

Maybe this code will give you some idea (is about 3D engineering views)....check ISO...

Code:
' COPYRIGHT DASSAULT SYSTEMES 2002
Option Explicit

' ***********************************************************************
'   Purpose     : Change viewpoint to an engineering view defined by a series of parameters.
'                 This macro is a sample: the presented engineering view has to be reworked knowing industrial standards.
'   Assumptions : A CATProduct document should be active.
'   Author      : 
'   Languages   : VBScript
'   Locales     : English
'   CATIA Level : V5R7
' ***********************************************************************
Sub CATMain()

  ' Parameters
  Const Front  = 0
  Const Back   = 1
  Const Right  = 2
  Const Left   = 3
  Const Bottom = 4
  Const Top    = 5
  Const Iso    = 6
  Const Custom = 7

  Const Sight = 0
  Const Up    = 1

  Const X = 0
  Const Y = 1
  Const Z = 2

  Dim StdDirection(7,1,2)

  StdDirection(Front , Sight, X) =  1.
  StdDirection(Front , Sight, Y) =  0.
  StdDirection(Front , Sight, Z) =  0.
  StdDirection(Front , Up   , X) =  0.
  StdDirection(Front , Up   , Y) =  0.
  StdDirection(Front , Up   , Z) =  1.

  StdDirection(Back  , Sight, X) = -1.
  StdDirection(Back  , Sight, Y) =  0.
  StdDirection(Back  , Sight, Z) =  0.
  StdDirection(Back  , Up   , X) =  0.
  StdDirection(Back  , Up   , Y) =  0.
  StdDirection(Back  , Up   , Z) =  1.

  StdDirection(Right , Sight, X) =  0.
  StdDirection(Right , Sight, Y) =  1.
  StdDirection(Right , Sight, Z) =  0.
  StdDirection(Right , Up   , X) =  0.
  StdDirection(Right , Up   , Y) =  0.
  StdDirection(Right , Up   , Z) =  1.

  StdDirection(Left  , Sight, X) =  0.
  StdDirection(Left  , Sight, Y) = -1.
  StdDirection(Left  , Sight, Z) =  0.
  StdDirection(Left  , Up   , X) =  0.
  StdDirection(Left  , Up   , Y) =  0.
  StdDirection(Left  , Up   , Z) =  1.

  StdDirection(Bottom, Sight, X) =  0.
  StdDirection(Bottom, Sight, Y) =  0.
  StdDirection(Bottom, Sight, Z) =  1.
  StdDirection(Bottom, Up   , X) =  0.
  StdDirection(Bottom, Up   , Y) =  1.
  StdDirection(Bottom, Up   , Z) =  0.

  StdDirection(Top   , Sight, X) =  0.
  StdDirection(Top   , Sight, Y) =  0.
  StdDirection(Top   , Sight, Z) = -1.
  StdDirection(Top   , Up   , X) =  0.
  StdDirection(Top   , Up   , Y) =  1.
  StdDirection(Top   , Up   , Z) =  0.

  StdDirection(Iso   , Sight, X) = -1./ Sqr(3)
  StdDirection(Iso   , Sight, Y) = -1./ Sqr(3)
  StdDirection(Iso   , Sight, Z) = -1./ Sqr(3)
  StdDirection(Iso   , Up   , X) = -1./ Sqr(6)
  StdDirection(Iso   , Up   , Y) = -1./ Sqr(6)
  StdDirection(Iso   , Up   , Z) =  2./ Sqr(6)

  StdDirection(Custom, Sight, X) =  1./ Sqr(3)
  StdDirection(Custom, Sight, Y) =  1./ Sqr(3)
  StdDirection(Custom, Sight, Z) = -1./ Sqr(3)
  StdDirection(Custom, Up   , X) =  1./ Sqr(6)
  StdDirection(Custom, Up   , Y) =  1./ Sqr(6)
  StdDirection(Custom, Up   , Z) =  2./ Sqr(6)

  ' Engineering view do display
  Dim iIndView As Integer
  '~ iIndView = Custom ' <==== To be changed on the different macros ====  this is original line, you have to change Custom with what you want as DS declare
  
   iIndView = 6 ' <==== To be changed on the different macros ====
   


  ' Get the viewer
  Dim oViewer As Viewer
  Set oViewer = CATIA.ActiveWindow.ActiveViewer

  ' Get the viewpoint
  Dim oViewpoint As Viewpoint3D
  Set oViewpoint = oViewer.Viewpoint3D

  ' Get the current parameters
  Dim Origin(2)
  oViewpoint.GetOrigin Origin
  Dim SightDirection(2)
  oViewpoint.GetSightDirection SightDirection
  Dim Focus As Double
  Focus = oViewpoint.FocusDistance

  ' Compute the new parameters
  Dim StdSightDirection(2)
  Dim StdUpDirection(2)
  Dim I As Integer
  For I = 0 to 2
    StdSightDirection(I) = StdDirection(iIndView,Sight,I)
    StdUpDirection(I) = StdDirection(iIndView,Up,I)
    Origin(I) = Origin(I) + Focus*(SightDirection(I) - StdSightDirection(I))
  Next

  ' Change the viewpoint
  oViewpoint.PutOrigin Origin
  oViewpoint.PutSightDirection StdSightDirection
  oViewpoint.PutUpDirection StdUpDirection
  oViewpoint.ProjectionMode = catProjectionCylindric

  ' Update the viewer
  oViewer.Update

  Set oViewpoint = Nothing
  Set oViewer = Nothing

End Sub

Regards
Fernando

- Romania
- EU
 
Thank you for another answer ferdo, unfortunately it didn't help again, but I was able to find the answer for myself. The vector I was looking for (V[sub]1[/sub]) is retrieved using the following formula:

V[sub]1[/sub] = (-1) * (V[sub]2[/sub] x (V[sub]1[/sub] x V[sub]2[/sub])), where V[sub]1[/sub] and V[sub]2[/sub] are vectors.

I wasn't able to find anything about the other topics and no one here answered as well, so I will assume it is impossible to change the "Raster Mode" from the view generation mode and the "Is always visible" option from the 3D Wireframe via vba and consider the topic answered.

Thank you for your help ferdo!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top