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 Add Additional Sheets to a Drawing 2

Status
Not open for further replies.

Cbaktis

Aerospace
May 17, 2013
13
US
Hi All,

I am very new to "macros" (it's been almost 12 years since I've played with VB scripting"). I am using a drawing template with 2 different sheet borders. I would like to write a macro that will do the following:

1. Add the new sheet
2. Add the new sheet frame (the frame is already created).
3. Modify the scale of the sheet to the same the first sheet (we use global scales for the drawing and each unique view may have there own).
4. Calculate the number of pages total and update sheet 1.

If someone can help me out that would be much appreciated.
 
Replies continue below

Recommended for you

@Cbaktis
If you want the scale of sheets to change when a parameter value changes, the best way is to use KWA logic. More specifically, via a "reaction" that gets triggered whenever the parameter value changes. You will need a KWA license.

As far as the code itself for changing the scale of drawing sheets, it's just:
Code:
Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument

Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets

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

drawingSheet1.Scale2 = 0.5

To be able to search for some of this code within the API documentation yourself, I suggest opening up CATIA V5's VBA Editor under Tools > Macro > Visual Basic Editor... or Alt+F11. You can then right click on the .catvba tool in the "Project" window on the left hand side and click Insert > Module then type in Sub CATMain () and End Sub. In between select Insert > Object resolution and then click the sheet in the tree. In the vba editor you can type in the object and then type "." to see what properties and methods are available via the API for that object (see step 4 in attached image). For example type "drawingSheet1.Scale" or "drawingSheet1.PageSetup". Put your cursor in the text "PageSetup" and hit F1 to bring up the API documentation (also attached).


That should get you started...
 
Hi drewmumaw,

Thank you for the tip. I was able to write the code no problem. I've looked and I don't think we have a KWA license (under tools->general->Licenses KWA says "no license"). Do you know any other options to have it autorun without needing the KWA license?
 
@Cbaktis
The other option would be to use a relation to link the view scales directly to the parameter. Screen grabs to come on my next post.
 
Step1: click f(x) then select the view scale from the list and click "Add Formula"

Step2: click the real parameter from the tree that you want the view scale linked to.

Now you should be able to change the parameter in the tree and see the view scale up and down accordingly.
 
Hi,

It is a real pleasure to see how this thread is going on, I should put a star somewhere for both of you, I'll do it now, is a nice example what can be done when peoples are talking.

@ drewmumaw - useful application for those who need, much better then others dealing with 3D text (from what I saw up to now).

Code bellow is adding a drawing view at a specific scale, 2:1 (maybe will help Cbaktis a little bit).

Code:
Language="VBSCRIPT"

Sub CATMain()

Dim drawingDocument1 As Document
Set drawingDocument1 = CATIA.ActiveDocument

Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets

Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.ActiveSheet

Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views

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

Dim drawingViewGenerativeBehavior1 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior

drawingViewGenerativeBehavior1.DefineFrontView 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000

drawingView1.x = 100
drawingView1.y = 400

Dim double1 As Double
double1 = drawingSheet1.Scale

drawingView1.Scale = 2.000000
drawingView1.Activate 

Dim specsAndGeomWindow1 As Window
Set specsAndGeomWindow1 = CATIA.ActiveWindow

Dim specsViewer1 As Viewer
Set specsViewer1 = specsAndGeomWindow1.ActiveViewer

specsViewer1.Reframe 

End Sub


Regards
Fernando

 
Code:
Hi Ferdo,

Thank you for the code and comments as well!

drewmumaw,

Sorry, I was away for the weekend! I did get scale script working, what we do here is use the same scale on all sheets of the drawing so I wrote a simple script which updates all the scales in the drawing to the user designated "DRAWING SCALE". The only issue I am having which is more a nuisance than anything else is that the start template that I created has a formual which basicalls sets '1\viewmakeup.1\scale'='DRAWING SCALE' and the same for each sheet is that when I change the DRAWING SCALE parameter it changes the shown scale to the same number. When I run the script, it sets the sheet scale to the right value but for some reason on sheet 1 and 2 (which were included in the start template) it doubles the scale (meaning 1/2 would become 1/4) that is shown on the f/d, but all views and drawing sheets scale to the correct scale. I will probably rework how I get the scale to show on the drawing and try to eliminate the formulas. The only other issue that I have is that since we don't have a KWA license is a way of deploying the scale change script automatically. The user feed back here is that they don't want to have to run a macro everytime to scale the drawing (thought it is much simplere than having to scale a lot of views). What I may do is create a GUI interface to deploy all the drawng related scripts in a menu set up and create a custom tool bar button with the the GUI load to that, so that in the drafting work bench users can launch the drawing scripts menu from there!

Here is the script that I have written:


Code:
Sub CATMain()

Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument

Dim parameters1 As Parameters
Set parameters1 = drawingDocument1.Parameters

Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets

j = drawingDocument1.Sheets.Count

Dim realParam1 As realParam
Set realParam1 = parameters1.Item("DRAWING SCALE")



For i = 1 to j

Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.Item(i)

drawingSheet1.Scale = realParam1.value

next

End Sub
 
@Cbaktis
Many companies deploy their macros in the way you described - by creating a custom toolbar. That sounds like a good idea.

With regards to Sheet.1 and Sheet.2 not scaling properly, a quick fix would be to just modify your loop at the end of your script to check if it's Sheet.1 or Sheet.2 and scale those sheets slightly differently in relation to your parameter DRAWING SCALE. The code would look like this:

Code:
For i = 1 To j

    Dim drawingSheet1 As DrawingSheet
    Set drawingSheet1 = drawingSheets1.Item(i)
    
    If drawingSheet1.Name = "Sheet.1" Or drawingSheet1.Name = "Sheet.2" Then
        drawingSheet1.Scale2 = realParam1.Value * 2
    Else
        drawingSheet1.Scale2 = realParam1.Value
    End If
    
Next

Regards,
Drew Mumaw
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top