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!

C/P from one drawing to another (background view to background view)

Status
Not open for further replies.

kicosh

Automotive
Mar 22, 2012
10
HR
Hello, i need some help here.
I am trying to create macro to paste everything from background view from template drawing to background view of active drawing sheet. Code needs to choose right sheet from template drawing and it does so by creating string from paper size and orientation on active sheet and some selection from combobox. this is pretty simple stuff. now my code opens template and choses right sheet and copies everything from background view but it fails on line where i need to add active sheets background view to selection (see code below). Error message i get is "Object doesnt support this property or method" and i really don't understand why. Also it gives same error if i try to add sheet to selection instead of view. After it pastes it should close template file but that should be simple enough. All objects in code that start with "t" are template ones and "o" are active sheet ones. I am using VBA. Catia V5R21

Thank you for your time

Code:
Private Sub btnImport_Click()


    Dim oDocs As Documents
    Set oDocs = CATIA.Documents

    Dim oDoc As DrawingDocument

    Set oDoc = CATIA.ActiveDocument
    
    Dim oSel As Selection
    Set oSel = oDoc.Selection

    Dim oSheets As DrawingSheets
    Set oSheets = oDoc.Sheets

    Dim oSheet As DrawingSheet
    Set oSheet = oSheets.ActiveSheet
    
    Dim oViews As DrawingViews
    Set oViews = oSheet.Views

    Dim obckView As DrawingView
    
    
    Dim ori As String
    Dim size As String
    Dim lang As String
    Dim SastName As String
    
    Select Case oSheet.Orientation
        Case 1
            ori = "L"
        Case 0
            ori = "P"
    End Select
    
    Select Case oSheet.PaperSize
        Case 2
            size = "A0"
        Case 3
            size = "A1"
        Case 4
            size = "A2"
        Case 5
            size = "A3"
        Case 6
            size = "A4"
    End Select
    
    Select Case Me.obLang1.Value
        Case True
            lang = "HR"
        Case False
            lang = "EN"
    End Select
    
    SastName = size & ori & "-" & lang & "-" & Me.cbSastavnica.Value
    
    
    Dim tDoc As DrawingDocument
    Set tDoc = oDocs.Open("E:\Scripts\Sastavnice.CATDrawing")
    
    Dim tSheets As DrawingSheets
    Set tSheets = tDoc.Sheets
    
    Dim tSheet As DrawingSheet
    Set tSheet = tSheets.Item(SastName)
    
    Dim tViews As DrawingViews
    Set tViews = tSheet.Views

    Dim tbckView As DrawingView
    Set tbckView = tViews.Item(2)
    
    Dim tSel As Selection
    Set tSel = tDoc.Selection
    
    tSel.Clear
    
    Dim tGeoElements As GeometricElements
    Set tGeoElements = tbckView.GeometricElements
    
    For Each tElement In tGeoElements
        tSel.Add (tElement)
    Next
    
    For Each tText In tbckView.Texts
        tSel.Add (tText)
    Next
    
    tSel.Copy

    
    
    oDoc.Activate
    Set obckView = oDoc.Sheets.ActiveSheet.Views.Item(2)
    
    oSel.Clear
    oSel.Add (obckView)  **************** BREAKS HERE ******************
    oSel.Paste


End Sub
 
Replies continue below

Recommended for you

i got solution from another forum:

"It looks like you probably just need to change:
oSel.Add (obckView)
to either Call oSel.Add (obckView)
or oSel.Add obckView

in VBA subroutine calls need to be prefixed with "Call" if you use parentheses around the arguments, or you not if you do not include parentheses.
You will also need to change the calls adding to the selection above it in the same way as they will throw the same error when you have elements or texts to copy. "


 
Hi

Well, searching forum should be first option for everyone... check this thread and somewhere at the end there is a macro which can be adapted to your needs (if is necessary). There are also few several threads related to background of the catdrawings.

Anyway, good that you solved your problem.

Regards
Fernando

- Romania
- EU
 
Ferdo thank you for reply.
i did search the forum and my code didn't work for some reasons that are still strange for me because i did what that guy from another forum proposed (only remove parentheses) and it worked. However, i did not remove parentheses from lines where texts and lines from background were added to selection. So, in a way, 2 different ways of calling subroutines were used and i don't understand why is this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top