Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Catia V5/V6 Frame and Title Block CreateSpline

AndersonC

Computer
Feb 20, 2025
4
Hello, I have been struggling with trying to create a spline using v6 vb net macro for the frame and title block. I am very new to this and am trying to create a logo. I have been able to create lines and circles but splines/curves have alluded me. I have tried multiple time, this is my latest attempt.

Code:
    ' Initialize CATIA
    Dim CATIA As Object
    Set CATIA = GetObject(, "CATIA.Application")
    
    ' Access the active drawing document
    Dim drawingDoc As DrawingDocument
    Set drawingDoc = CATIA.ActiveDocument
    
    ' Access the drawing sheet
    Dim drawingSheet As DrawingSheet
    Set drawingSheet = drawingDoc.Sheets.Item(1)
    
    ' Access the drawing view
    Dim drawingView As DrawingView
    Set drawingView = drawingSheet.Views.Item(1)
    
    ' Access the Factory2D
    Dim factory2D As Factory2D
    Set factory2D = drawingView.Factory2D
    
    ' Define the points for the spline
    Dim points(2) As Point2D
    Set points(0) = factory2D.CreatePoint(0, 0)
    Set points(1) = factory2D.CreatePoint(10, 10)
    Set points(2) = factory2D.CreatePoint(20, 0)
    
    ' Create a SafeArray to hold the points
    Dim poles As Variant
    poles = CATIA.CreateObject("CATSafeArrayVariant")
    poles.SetArray points
    
    ' Create the spline
    Dim spline As Spline2D
    Set spline = factory2D.CreateSpline(poles)
    spline.Name = "ProjSpline1"
    
    ' Add the spline to the selection
    MyCATIA.ActiveDocument.Selection.Add spline
    
    ' Set visual properties for the spline
    Dim visProperties1 As VisPropertySet
    Set visProperties1 = MyCATIA.ActiveDocument.Selection.VisProperties
    visProperties1.SetRealWidth 2 * inch, 0.25 * inch
    
    ' Update the drawing
    drawingDoc.Update

Any help with this would be greatly appreciated.
 
Replies continue below

Recommended for you

Hi , i did not searched in documentation , but just saying , it is not easily to bring a picture with the logo ?
 
Hi , i did not searched in documentation , but just saying , it is not easily to bring a picture with the logo ?
I did try this, however I kept being met with a "object or property is not supported."
 
There is an API to add a picture to a drawing view (I didn't test but it may only support certain file types, so check that if you are having issues):

Function Add(CATBSTR iDrawingPicturePath,double iPositionX,double iPositionY) As DrawingPicture

Inserts a drawing picture in the drawing view and adds it to the DrawingPictures collection.

Parameters:
iDrawingPicturePath

The path of the picture file (ex : "C:\tmp\ball.bmp").

iPositionX, iPositionY
The drawing picture x and y coordinates, expressed in millimeters, with respect to the drawing view coordinate system

Returns: The inserted drawing picture

Example:
The following example inserts a drawing picture from a given picture file path The MyView is the active view in the active drawing sheet

Code:
Dim MySheet As DrawingSheet
Set MySheet = CATIA.ActiveDocument.Sheets.ActiveSheet
Dim MyView As DrawingView
Set MyView = MySheet.Views.ActiveView
Dim MyDrawingPicture1 As DrawingPicture
Set MyDrawingPicture1 = MyView.Pictures.Add("C:\tmp\ball.bmp", 100., 50.)
 
There is an API to add a picture to a drawing view (I didn't test but it may only support certain file types, so check that if you are having issues):

Function Add(CATBSTR iDrawingPicturePath,double iPositionX,double iPositionY) As DrawingPicture

Inserts a drawing picture in the drawing view and adds it to the DrawingPictures collection.

Parameters:
iDrawingPicturePath

The path of the picture file (ex : "C:\tmp\ball.bmp").

iPositionX, iPositionY
The drawing picture x and y coordinates, expressed in millimeters, with respect to the drawing view coordinate system

Returns: The inserted drawing picture

Example:
The following example inserts a drawing picture from a given picture file path The MyView is the active view in the active drawing sheet

Code:
Dim MySheet As DrawingSheet
Set MySheet = CATIA.ActiveDocument.Sheets.ActiveSheet
Dim MyView As DrawingView
Set MyView = MySheet.Views.ActiveView
Dim MyDrawingPicture1 As DrawingPicture
Set MyDrawingPicture1 = MyView.Pictures.Add("C:\tmp\ball.bmp", 100., 50.)
Thank you for your reply. I did come across this function and when I used it, the code did run, but unfortunately, I did not get an image of any kind when i ran the script. I also did not get an error. I assumed it was running however, I tried giving just it a couple different file types besides .bmp. Then I changed the file path to a bad path, still no error. So I am now doubtful this is actually running...
 
Just ran this code in the native built in macro editor (written in VBA) and it dumps the image directly into the drawing. No update required; it just shows up as soon as the code runs. I have also used this same command from an external application written in VB.NET, so I know it works there as well.

**Obviously point the file path to your image location.

Code:
Sub CATMain()
    Dim DrwDoc As DrawingDocument
    Set DrwDoc = CATIA.ActiveDocument
    
    Dim MySht As DrawingSheet
    Set MySht = DrwDoc.Sheets.Item(1)
    
    Dim BGView As DrawingView
    Set BGView = MySht.Views.Item(2)
    
    BGView.Pictures.Add "C:\SampleImg.bmp", 0, 0
End Sub
 

Part and Inventory Search

Sponsor