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!

VBA code to insert the customized symbol in catia drawing which can be replaced using excel file 2

Status
Not open for further replies.

Ajaypatil8458

Aerospace
May 15, 2020
12
IN
Hello,

I have saved some views as a symbol which I am currently in inserting into the CATIA drawing using Catalog option. I need to change these symbols with the input provided in design table excel sheet.

Is there any way to do this with VBA code or for that matter with parametric modelling?


Any help related to this is greatly appreciated.

Thanks,
Vijay
 
Replies continue below

Recommended for you

Hi.

Build a drawing component that exposes adjustable parameters and the use DrawingView.Components to place instances of it and modify their parameters.
 
Hello,

Thank you for your response.
But could you please elaborate your suggestion, i am not quite understanding what you are suggesting.

I do have a model where i have created parameters which i can link with the drawing view. But I am stuck with how to insert that symbol as view and how to link it with parameter.

Thank you,

Vijay
 
Refer to "Modifying Annotation Text and Orientation in a 2D Component Instance" article in documentation.
 
Hello,

Thank you for your help,

I have gone through the documents and created 2D instances which can be replaced using "replace reference" (And as I understand all these instances should be created in same drawing to replace them, am I right?) but I am still not able to link these 2D component with parameters that i have created in drawing. Am I doing something incorrectly. (I am looking for linking these 2D components to get replaced with the parameters that are linked with design table)

please see attached "drawing representation" screenshots for more information. I am trying to replace the "symbol 1 with Symbol 3" and "symbol 2 with symbol 1" and so forth. I have also created the parameter in drawing file to link with 2D components that I have created but i am not able to link those with parameter (See attached screenshots for more information)



Could you please guide on that front.

Thank you,

Vijay


 
I am trying to replace the "symbol 1 with Symbol 3" and "symbol 2 with symbol 1" and so forth.

Ok, I finally get it, thanks for explaining.
I'll check what can be done tomorrow.

Meanwhile, do you have excel table linked to CATIA as "Design Table" component? Do you need help with getting values from that table iwith VB?
 
Hello,

Yes I do have design tables which are linked with CATIA Component as well CATIA drawing. I have linked the values from table with CATIA drawing (Like title block info and some notes on drawing view) by creating the parameters.
For example i have created the parameter named "Stock Size" which is linked to excel sheet (Design table) and i am linking that parameter with the note available on CATIA drawing using Attribute Link.

Although I am not able to replace whole symbols using same method.
Thank you for helping me on this one, really appreciated your help.

Regards...Vijay
 
Although I am not able to replace whole symbols using same method.

That's true, it's not possible.

Here's the snippet to get reference 2D component from another document (which is used as a "catalog"), find it's instances in active view and replace them with another 2D component:

Code:
Dim componentCatalog as DrawingDocument
set componentCatalog = CATIA.Documents.Item("C:\SomeCatalog.CATDrawing")

Dim newComponentRef as DrawingView
set newComponentRef = componentCatalog.Sheets.ActiveSheet.Views.Item("NEW SYMBOL")

' find instance of the "OLD SYMBOL" in current view
Dim currentView as DrawingView
set currentView = CATIA.ActiveDocument.Sheets.ActiveSheet.Views.ActiveView

Dim oldComponents: set oldComponents = CreateObject("System.Collections.ArrayList")
Dim comp: for each comp in currentView.Components
  if comp.CompRef.Name = "OLD SYMBOL" then
    oldComponents.Add comp
  end if
next

' create new instances, select and delete old ones
Dim sel as Selection
set sel = CATIA.ActiveDocument.Selection
sel.Clear
for each comp in oldComponents
  currentView.Components.Add newComponentRef, comp.X, comp.Y
  sel.Add comp
next
sel.Delete
 
Hello,

Thank you for the Macro.

I am quite new for VBA coding, thank you for helping in creating the Macro. I have used this Macro but I am getting some compile error. I have attached the CATIA files for your reference n case there is any problem with catalog part.

My ultimate aim is to replace these symbols by giving input in excel sheets or in design table & I think it will possible to provide excel input in VBA itself, right?

Thank you for all your help & sorry for coming back again and again but it will be really helpful in case I get this one resolved.

Regards...Vijay

 
Ok, I see.
CATIA is a keyword that refers to the running session.
Never name your macros CATIA.catvba :)
 
You still have your library named CATIA (look at the project explorer window on the left).

Recreate .catvba
 
hmmm... change the CATIA name to something else, just highlight the top row, and little further down you will be able to change the name of your VBA project. But this is only one small error...
you then define componentCatalog as a DrawingDocument?...
so you have to proceed and refer/set a CATDrawing...
then you dim a DrawingView, and you proceed to set view as "SYMBOL 4" from your ActiveSheet--but I could only find "SYMBOL 3"?

regards,
LWolf
 
Still getting same compilation error.

I doubt you've done what I asked for.
In such case right-click on the "CATIA" project in Project Explorer window, select "Properties" and change it's "Name" to "TEST".

See LWolf's comment as well.
 
Hello,

yes You both are right, the name was still CATIA, did not realize about renaming it in properties.
Now I have updated the name and the symbol name but still getting same compilation error.

I am not getting what I am missing.

It is working at your end..

Sorry for all this mess, and really appreciated your help.

Regards...Vijay

 
Ok, this below definitely works but requires SomeCatalog.CATDrawing to be opened in CATIA session:

Code:
Option Explicit

Sub CATMain()
    Dim componentCatalog As DrawingDocument
    Set componentCatalog = CATIA.Documents.item("SomeCatalog.CATDrawing")
    
    Dim newComponentRef As DrawingView
    Set newComponentRef = componentCatalog.Sheets.ActiveSheet.views.item("NEW SYMBOL")
    
    ' find instance of the "OLD SYMBOL" in current view
    Dim currentView As DrawingView
    Set currentView = CATIA.ActiveDocument.Sheets.ActiveSheet.views.ActiveView
    
    Dim oldComponents: Set oldComponents = CreateObject("System.Collections.ArrayList")
    Dim comp
    If currentView.components.Count > 0 Then
        For Each comp In currentView.components
        If comp.CompRef.name = "OLD SYMBOL" Then
            oldComponents.Add comp
        End If
        Next
    End If
    
    ' create new instances, select and delete old ones
    If oldComponents.Count > 0 Then
        Dim sel As Selection
        Set sel = CATIA.ActiveDocument.Selection
        sel.Clear
        For Each comp In oldComponents
          currentView.components.Add newComponentRef, comp.x, comp.y
          sel.Add comp
        Next
        sel.Delete
    End If
    
End Sub
 
No, I can't open your files because of version incompatibility.

What CATIA release do you use?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top