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?
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?
RE: How can I get a File Name in Sketch?
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
RE: How can I get a File Name in Sketch?
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 SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: How can I get a File Name in Sketch?
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?
Or just add this to the initial code to clarify all:
Msgbox oParent.Name
Msgbox oParent.Path 'Full Path
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: How can I get a File Name in Sketch?
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
RE: How can I get a File Name in Sketch?
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 SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: How can I get a File Name in Sketch?
Your script solved my problem!
You are my saviour!! You saved me!!!
Now I can sleep deeply and work tomorrow with smile!!! ;)