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. Align Views on a draft

Status
Not open for further replies.

JoJo_Laser

Automotive
Aug 22, 2017
3
IT
I am doing a macro for obtaining sections of an object and putting them in a sheet.
Now I can do the sections but I still don't understand how to fit them in the sheet.
For example.
3 sections in a sheet: macro do the sections, and moves them in these positions:
-----------------------------------
| ---- --------- ---- |
| | | | | | | |
| | | | | ---- |
| ---- | | |
| --------- |
-----------------------------------
I have the dimensions of the sections (not included the dimensions of the box, but they are different for different objects!) but I don't know which command I must use for move them in rows and columns.
I know there is the method (drawingView).x and (drawingView).y but they set the position of the CENTER of the section, so it is not so precise if I must align the sections in a row.
Furthermore, how can I know the dimensions of the section plus the box?!

Please, tell me at least if the question is clear, I am not english speaker (you don't say?!)
 
Replies continue below

Recommended for you

Hi,

Welcome to this forum.

See if this will help you to find the box dimensions of a sample view (named Front view), then, with a little math you can find the center of the box...

Code:
Language="VBSCRIPT"
Sub CATMain()
Set drawingDocument1 = CATIA.ActiveDocument
Set drawingSheets1 = drawingDocument1.Sheets
Set drawingSheet1 = drawingSheets1.Item("Sheet.1")
Set drawingViews1 = drawingSheet1.Views
Set drawingView1 = drawingViews1.Item("Front view")
Dim BoundingBox(3)
drawingView1.Size BoundingBox
msgbox BoundingBox(0) & " " & BoundingBox(1) & " " & BoundingBox(2) & " " & BoundingBox(3)
end sub



Regards
Fernando

- Romania
- EU
 
Thank you for your welcome and for your help.
However, I did not understand how to program macro for catia for drafting ambient.
I began the record, I set the drafting, a casual front and a casual section.
This is the code:

"
Code:
Language="VBSCRIPT"


Sub CATMain()

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim drawingDocument1 As Document
Set drawingDocument1 = documents1.Add("Drawing")

drawingDocument1.Standard = catISO

Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets

Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.Item("Foglio.1")

drawingSheet1.PaperSize = catPaperA0

drawingSheet1.Scale = 1.000000

drawingSheet1.Orientation = catPaperLandscape

Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views

Dim drawingView1 As DrawingView
Set drawingView1 = drawingViews1.Add("AutomaticNaming")

Dim drawingViewGenerativeLinks1 As DrawingViewGenerativeLinks
Set drawingViewGenerativeLinks1 = drawingView1.GenerativeLinks

Dim drawingViewGenerativeBehavior1 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior

Dim partDocument1 As Document
Set partDocument1 = documents1.Item("Part1.CATPart")

Dim product1 As CATBaseDispatch
Set product1 = partDocument1.GetItem("Part1")

drawingViewGenerativeBehavior1.Document = product1

drawingViewGenerativeBehavior1.DefineFrontView 0.809714, -0.465847, -0.356860, -0.586824, -0.642788, -0.492404

drawingView1.x = 594.500000

drawingView1.y = 420.500000

drawingView1.Scale = 1.000000

Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior

drawingViewGenerativeBehavior1.Update 

drawingView1.Activate 

Set drawingDocument1 = CATIA.ActiveDocument

Set drawingSheets1 = drawingDocument1.Sheets

Set drawingSheet1 = drawingSheets1.ActiveSheet

Set drawingViews1 = drawingSheet1.Views

Set drawingView1 = drawingViews1.ActiveView

Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior

Dim drawingView2 As DrawingView
Set drawingView2 = drawingViews1.Add("AutomaticNaming")

Dim drawingViewGenerativeBehavior2 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior2 = drawingView2.GenerativeBehavior

drawingView2.x = 338.903315

drawingView2.y = 605.738502

Dim double1 As Double
double1 = drawingView1.Scale

drawingView2.Scale = 1.000000

Dim double2 As Double
double2 = drawingView1.Angle

drawingView2.Angle = 0.000000

[COLOR=#CC0000]Dim arrayOfVariantOfDouble1(3)
arrayOfVariantOfDouble1(0) = 46.166950
arrayOfVariantOfDouble1(1) = 63.702304
arrayOfVariantOfDouble1(2) = -68.664461
arrayOfVariantOfDouble1(3) = -94.744928[/color]
drawingViewGenerativeBehavior2.DefineSectionView arrayOfVariantOfDouble1, "SectionCut", "Offset", 0, drawingViewGenerativeBehavior1

Dim drawingViewGenerativeLinks2 As DrawingViewGenerativeLinks
Set drawingViewGenerativeLinks2 = drawingView2.GenerativeLinks

Set drawingViewGenerativeLinks1 = drawingView1.GenerativeLinks

drawingViewGenerativeLinks1.CopyLinksTo drawingViewGenerativeLinks2

Set drawingViewGenerativeBehavior2 = drawingView2.GenerativeBehavior

drawingViewGenerativeBehavior2.Update 

drawingView2.ReferenceView = drawingView1

drawingView2.AlignedWithReferenceView 

End Sub
"
In the macro that I built (this is not represented!), I have got an array in which there are the coordinates of the different sections (the arrayofdouble above).

I want to do something like:

For i = 0 To n (i=index of intersection, n=total of sections)
arrayOfVariantOfDouble(i) = ...
arrayOfVariantOfDouble(i+1) = ...
arrayOfVariantOfDouble(i+2) = ...
arrayOfVariantOfDouble(i+3) = ...
Next

And positioning the different sections along rows and columns.

I see a lot of code that I don't get, such as

Code:
Dim drawingViewGenerativeLinks2 As DrawingViewGenerativeLinks
Set drawingViewGenerativeLinks2 = drawingView2.GenerativeLinks

Set drawingViewGenerativeLinks1 = drawingView1.GenerativeLinks

drawingViewGenerativeLinks1.CopyLinksTo drawingViewGenerativeLinks2

Set drawingViewGenerativeBehavior2 = drawingView2.GenerativeBehavior

drawingViewGenerativeBehavior2.Update
Which part I must include in the loop, for avoiding a lot of redudant objects? (ex: drawingViewGenerativeBehavior2-3-4-5-6-7-...-n , one for section).

One last question: are you sure that (drawingView).x/y is a method that sets the position of the CENTER of the view? Because sometimes it seems it is not the center...
 
For your last question, check picture below, if you will change anchor point for the text, it will change box position.
Capture_tv0vzk.jpg


Regards
Fernando

- Romania
- EU
 
according to CHM file drawingView.x(/y) is used to position the origin of the view.

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top