×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How can I get a File Name in Sketch?

How can I get a File Name in Sketch?

How can I get a File Name in Sketch?

(OP)
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?

RE: How can I get a File Name in Sketch?

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?

RE: How can I get a File Name in Sketch?

(OP)
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 --> VBA

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 

RE: How can I get a File Name in Sketch?

Hi,

See if is it working...

CODE --> CATScript

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

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: How can I get a File Name in Sketch?

(OP)
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 :)

RE: How can I get a File Name in Sketch?

(OP)
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 --> VBA

MsgBox CATIA.ActiveDocument.Name
MsgBox CATIA.ActiveDocument.Path
MsgBox CATIA.ActiveDocument.FullName 

RE: How can I get a File Name in Sketch?

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 --> CATScritp

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

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: How can I get a File Name in Sketch?

(OP)
Hey, FERDO

Your script solved my problem!

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

Now I can sleep deeply and work tomorrow with smile!!! ;)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources