Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

How can I get a File Name in Sketch?

Status
Not open for further replies.

tpalsl125

Automotive
Apr 24, 2015
44
Hello, all

I'm trying to make some macro.

But I didn't solve to get a file name in Sketch.

ALSO I know how to get a Catia Name(Part Number), a Instance Name and an object name in Sketch.

But I don't really have no idea to get a File name in Sketch.

Can somebody help me or give me some tips?
 
Replies continue below

Recommended for you

Please explain what you mean by "file name in sketch". Do you want the part's number to appear in a sketch so it can be embossed/raised on a part in 3D?
 
Hello, lardman. Thanks for your reply.

I meant, when I am in "Sketcher" Mode and select an element(Point2D, Line2D, etc..),

how can I get a File name? Not Catia name(Part Number) and Catia instance name.

Here is my script which I found on Google and I modified a little bit.

Of course, I know the 'FullName' method can get a full path of the part when I select only 'Product'.

But I want to get a full path or file name only when I am in "Sketcher" mode.

Could you help me solve this point?

Code:
Set Sel1 = CATIA.ActiveDocument.Selection
Set SelObj1 = Sel1.Item(1).Value
MsgBox "* Type Name *" &Chr(10)& TypeName(SelObj1)
MsgBox "* Instance Name *" &Chr(10)& SelObj1.Name

WinName1 = SelObj1.ReferenceProduct.Parent.FullName
MsgBox "* Catia Window Name *" &Chr(10)& WinName1
 
Hi,

See if is it working...

Code:
Sub CATMain()
    Dim oDoc As Document
    Dim oPart As Part
    Dim oObject As AnyObject
    Dim cSelection ' As Selection
    Dim Status As String
    Dim InputObjectType(0)
    Dim sPath As String
    Dim i As Integer
    Dim oParent As AnyObject
   
    Set oDoc = CATIA.ActiveDocument    
    Msgbox "This macro will find the path for an element in a CATPart"   
    '### SELECT SOMETHING ###
    Set cSelection = oDoc.Selection
    cSelection.Clear
    InputObjectType(0) = "AnyObject"
    Status = cSelection.SelectElement2(InputObjectType, "Select an Element", True)
    If (Status = "Cancel") Then
        MsgBox "nothing selected.", vbInformation, "Error"
        Exit Sub
    End If
   
    Set oObject = cSelection.Item(1).Value
    cSelection.Clear
    '### END SELECTION ###   
    '### FIND PATH ###
    i = 1
    Set oParent = oObject
    sPath = "/" & oObject.Name
    Do        
        sPath = "/" & oParent.Name & sPath
        Set oParent = oParent.Parent
        i = i + 1
    Loop Until TypeName(oParent) = "PartDocument" Or i = 20    
    Msgbox "sPath: " & Right(sPath, Len(sPath) - 1)
   
End Sub

Regards
Fernando

- Romania
- EU
 
Hello, Ferdo. Thanks for your script.

Your script can find the path in Catia tree..

I meant I want to find a path of a File in 'Sketcher' mode.. ex) "C:\Users\Desktop\Part1.CATPart"

Not "Product.1\Part.1\Geometrical Set.1\Sketch.1\Point.1"

I know only to use 'FullName' method.

But this can't work in "Sketcher" mode. And I must select a "Product".

Do you have some ideas? Please, be my HERO :)
 
Thanks for your reply.

I just tried to use below script. But I didn't get a result what I want.

Because I have a Product that has included a Part.

I have to know "01_101__Lower Insert Steel"'s file name, not a Catia name, when I'm in "Sketcher" Mode.

Code:
MsgBox CATIA.ActiveDocument.Name
MsgBox CATIA.ActiveDocument.Path
MsgBox CATIA.ActiveDocument.FullName

11111111_gfef0y.jpg
 
Interesting...if you will put the whole code in a CATScript will do the job, no mater what you will select and where you are active (Sketcher or what ever...).

Look more carefully at the code and follow his workflow, when you do the selection is "AnyObject" , then you will find the name of the parent of the selection... there are lines there which are not useful for your purpose (just to let you know it can be done also in different ways).

For me is working fine.

Code:
Sub CATMain()
    Dim oDoc As Document
    Dim oPart As Part
    Dim oObject As AnyObject
    Dim cSelection ' As Selection
    Dim Status As String
    Dim InputObjectType(0)
    Dim sPath As String
    Dim i As Integer
    Dim oParent As AnyObject
   
    Set oDoc = CATIA.ActiveDocument    
    Msgbox "This macro will find the path for an element in a CATPart, CATPart name and CATPart path"   
    '### SELECT SOMETHING ###
    Set cSelection = oDoc.Selection
    cSelection.Clear
    InputObjectType(0) = "AnyObject"
    Status = cSelection.SelectElement2(InputObjectType, "Select an Element", True)
    If (Status = "Cancel") Then
        MsgBox "nothing selected.", vbInformation, "Error"
        Exit Sub
    End If
   
    Set oObject = cSelection.Item(1).Value
    cSelection.Clear
    '### END SELECTION ###   
    '### FIND PATH ###
    i = 1
    Set oParent = oObject
    sPath = "/" & oObject.Name
    Do        
        sPath = "/" & oParent.Name & sPath
        Set oParent = oParent.Parent
        i = i + 1
    Loop Until TypeName(oParent) = "PartDocument" Or i = 20    
    Msgbox "sPath: " & Right(sPath, Len(sPath) - 1)
    Msgbox oParent.Name
    Msgbox oParent.Path 'Full Path

   
End Sub


Regards
Fernando

- Romania
- EU
 
Hey, FERDO

Your script solved my problem!

You are my saviour!! You saved me!!!

Now I can sleep deeply and work tomorrow with smile!!! ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor