×
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!

*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

Conversion of Tree from Chineese to English
3

Conversion of Tree from Chineese to English

Conversion of Tree from Chineese to English

(OP)
I recieved a Solidworks file from a Chineese supplier.  The tree is in Chineese.  Is it possible to convert the tree to english without haveing to individually rename each item?

RE: Conversion of Tree from Chineese to English

2
In my opinion it is impossible to do this. Since all the names of the features were hardcoded by the user and it is no any reference to localization names.

The only solution I can see in this situation is to write a macro which will rename all feature to its type name.

For example all reference plane will be named as "RefPlane1", "RefPlane2", "RefPlane3"...

all sketches as "ProfileFeature1", "ProfileFeature2"...
all Extruded features as "Extrusion1", "Extrusion2"...

It is also possible to set some specific name for the most common types. For example use "Sketch" instead of "ProfileFeature".

Please let me know whether this workaround is acceptable to you. I can help with writing of the macro.

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com

RE: Conversion of Tree from Chineese to English

(OP)
I was just wondering if there was some sort of switch - thank you for your response

RE: Conversion of Tree from Chineese to English

ArtemTat,

Can you create the macro you discussed above. I have been looking for a macro like this.

TIA

Deepak Gupta
SW2009 SP3.0
SW2007 SP5.0

RE: Conversion of Tree from Chineese to English

Sure Deepak,

Please find it below. Note you can predefine base name for specific type of features. For example in this case the sketches has the TypeName == "ProfileFeature" but we used to see it as "Sketch", so <dicBaseNames.Add "ProfileFeature", "Sketch"> line will generate "Sketch" name instead of "ProfileFeature" one. You can add as many lines as you like.

It is also possible to improve the macro to do not add the increment to some types of features (i.e Materials). Please let me know whether you need this.

- - - - - - - - - - - - - - -
Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.PartDoc
Dim swFeat As SldWorks.Feature
Dim newName As String

Dim dicFeatsCount As Object

Dim dicBaseNames As Object

Sub main()

    Set dicFeatsCount = CreateObject("Scripting.Dictionary")
    
    Set dicBaseNames = CreateObject("Scripting.Dictionary")
    
    'Add the list of predefined base names
    '- - - - - - - - - - - - - - - - - - - -
    dicBaseNames.Add "ProfileFeature", "Sketch"
    dicBaseNames.Add "Extrusion", "Extrude"
    dicBaseNames.Add "RefPlane", "Plane"
    '- - - - - - - - - - - - - - - - - - - -

    Set swApp = Application.SldWorks
    
    Set swPart = swApp.ActiveDoc
    
    Set swFeat = swPart.FirstFeature
    
    While Not swFeat Is Nothing
        
        If dicFeatsCount.exists(swFeat.GetTypeName2()) Then
            dicFeatsCount.Item(swFeat.GetTypeName2()) = dicFeatsCount.Item(swFeat.GetTypeName2()) + 1
        Else
            dicFeatsCount.Add swFeat.GetTypeName2(), 1
        End If
        
        If dicBaseNames.exists(swFeat.GetTypeName2()) Then
            newName = dicBaseNames.Item(swFeat.GetTypeName2())
        Else
            newName = swFeat.GetTypeName2()
        End If
        
        newName = newName & dicFeatsCount.Item(swFeat.GetTypeName2())
        
        swFeat.Name = newName
        
        Set swFeat = swFeat.GetNextFeature
        
    Wend
    
End Sub
- - - - - - - - - - - - - - -

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com

RE: Conversion of Tree from Chineese to English

Thanks Artem. I will check this and let you know.

 

Deepak Gupta
SW2009 SP3.0
SW2007 SP5.0

RE: Conversion of Tree from Chineese to English

Works great as required. And yes, I need your help again to avoid adding the increment to some types of features like Materials.

Deepak Gupta
SW2009 SP3.0
SW2007 SP5.0

RE: Conversion of Tree from Chineese to English

Deepak,

I can see two possible solutions in this situation:

1) Add some list of features which shouldn't be incremented. Similar to the list for base names.

2) Do not add the increment to first feature. For example we have two Extrude features. The first feature will be named as "Extrude" and second one "Extrude1". In this case the single feature like "Materials" won't have the incremement.

What solution is more acceptable to you?

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com

RE: Conversion of Tree from Chineese to English

Artem,

Thanks for heads up. Both method looks good. If possible can you examples/codes with both of them. Being a beginner with SW macros/API, I will be learning new stuff with your codes.

Thanks a lot for the help.

Deepak Gupta
SW2009 SP3.0
SW2007 SP5.0

RE: Conversion of Tree from Chineese to English

Thanks a lot Artem.
 

Deepak Gupta
SW2009 SP3.0
SW2007 SP5.0

RE: Conversion of Tree from Chineese to English

Artem,

Tried both of the macro and they worked well.

I have few more questions in relation with the macro:

1 How to avoid renaming of the material. Both the macro rename the material name to material. For e.g. if I have given Brass as a material to the part, then both the macro will rename Brass to material.

2 Same happens with the default plane.

What code line I should be adding to avoid the above issues.

Thanks a lot for the help and sharing.

Deepak Gupta
SW2009 SP3.0
SW2007 SP5.0
MathCAD 14.0

RE: Conversion of Tree from Chineese to English

Hi Deepak,

I've missed the material issue.

Please take a look at this modified macro which considers the material name as well as standard reference geometry names. I've created four constants for their names.

Please do not hesitate to as a question if you have ones.

- - - - - - - - - - - - - -
Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.PartDoc
Dim swFeat As SldWorks.Feature
Dim newName As String

Dim dicFeatsCount As Object

Dim collFeatsNonIncr As Collection
Dim dicBaseNames As Object

Const FrontPlane = "Front Plane"
Const TopPlane = "Top Plane"
Const RigthPlane = "Rigth Plane"
Const Origin = "Origin"

Dim isRefGeom As Boolean

Sub main()

    Set dicFeatsCount = CreateObject("Scripting.Dictionary")
    
    Set collFeatsNonIncr = New Collection
    
    Set dicBaseNames = CreateObject("Scripting.Dictionary")
    
    isRefGeom = False
    
    'Add the list of features which shouldn't be incremented
    '- - - - - - - - - - - - - - - - - - - -
    collFeatsNonIncr.Add "SensorFolder"
    collFeatsNonIncr.Add "DocsFolder"
    collFeatsNonIncr.Add "DetailCabinet"
    collFeatsNonIncr.Add "MaterialFolder"
    collFeatsNonIncr.Add "OriginProfileFeature"
    '- - - - - - - - - - - - - - - - - - - -
    
    'Add the list of predefined base names
    '- - - - - - - - - - - - - - - - - - - -
    dicBaseNames.Add "MaterialFolder", "Material <not specified>"
    dicBaseNames.Add "OriginProfileFeature", "Origin"
    dicBaseNames.Add "ProfileFeature", "Sketch"
    dicBaseNames.Add "Extrusion", "Extrude"
    dicBaseNames.Add "RefPlane", "Plane"
    '- - - - - - - - - - - - - - - - - - - -

    Set swApp = Application.SldWorks
    
    Set swPart = swApp.ActiveDoc
    
    Set swFeat = swPart.FirstFeature
    
    While Not swFeat Is Nothing
        
        If dicFeatsCount.exists(swFeat.GetTypeName2()) Then
            dicFeatsCount.Item(swFeat.GetTypeName2()) = dicFeatsCount.Item(swFeat.GetTypeName2()) + 1
        Else
            dicFeatsCount.Add swFeat.GetTypeName2(), 1
        End If
        
        If dicBaseNames.exists(swFeat.GetTypeName2()) Then
            newName = dicBaseNames.Item(swFeat.GetTypeName2())
        Else
            newName = swFeat.GetTypeName2()
        End If
        
        Dim i As Integer
        
        Dim isIncremented As Boolean
        isIncremented = True
        For i = 1 To collFeatsNonIncr.Count
            If collFeatsNonIncr(i) = swFeat.GetTypeName2() Then
                isIncremented = False
                Exit For
            End If
        Next
        
        If isIncremented Then
            newName = newName & dicFeatsCount.Item(swFeat.GetTypeName2())
        End If
        
        If swFeat.GetTypeName2 = "MaterialFolder" Then
            
            isRefGeom = True
            
            Dim sMatName As String
            
            sMatName = swPart.GetMaterialPropertyName2("", "")
            
            If sMatName <> "" Then
                newName = sMatName
            End If
            
        End If
        
        swFeat.Name = newName
        
        Set swFeat = swFeat.GetNextFeature
        
        If isRefGeom Then
            
            swFeat.Name = FrontPlane
            
            Set swFeat = swFeat.GetNextFeature
            swFeat.Name = TopPlane
            
            Set swFeat = swFeat.GetNextFeature
            swFeat.Name = RigthPlane
            
            Set swFeat = swFeat.GetNextFeature
            swFeat.Name = Origin
                
            Set swFeat = swFeat.GetNextFeature
            isRefGeom = False
        End If
        
    Wend
    
End Sub
- - - - - - - - - - - - - -

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com

RE: Conversion of Tree from Chineese to English

Works  great.

Thanks a lot.

Deepak Gupta
SW2009 SP3.0
SW2007 SP5.0
MathCAD 14.0

RE: Conversion of Tree from Chineese to English

ArtemTat,

Thanks for this. I gave you the other star. I have some tooling files that were created collaboratively with a Chineese vendor on a design I created. I made a copy of one part with Chinese, checked this macro out, and for the most part wiped out the Chinese on the features they created.

Before I go open the assembly, which is rather large, and is very heavy with in-context relationships, I'm wondering if running this is going to reek havoc with these in-context relationships and equations that reference the names of planes/sketches/features.

I thinking it will be ok, as I can change the name of something in the part that is used in-context in the assembly, and the assembly will rebuild fine, but then again, one thing could fail, like the assem not being able to find the plane whose name changed created from a feature who's name changed created from a sketch who's name changed (you get my point) from this translation, and then down comes the whole house of cards. Anyone have any guesses. I guess the best way is to make a copy and try, but if someone can answer this quickly it would be much apprecieated.

rfus

RE: Conversion of Tree from Chineese to English

rfus,

I have also a problems with in-context equations from my end. When I open a part separately and run the macro and then get back to assembly the in-context equations fail. Hovewer I can see the same behavior from the UI. But when I rename the feature from the assembly from the UI equations updated automatically. So I  have changed the macro to work from assembly but this isn't fix the issue. I have used different method ModelDoc2::SelectedFeatureProperties which is recorded by the macro while renaming the feature but the problem still here. So I think it can be considered as a bug in SolidWorks API: methods ModelDoc2::SelectedFeatureProperties and Feature::Name don't update the string reference in the equation. And renaming from the UI do this.

I believe this problem can be fixed using the IEquationMgr APIs.

BTW. I have no problem with the in-context relations. If I have for example the sketch at the assembly level which was created on the plane in component. And the plane was renamed by the macro. The reference updated correctly from my end.

Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com

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! Already a Member? Login


Resources

Engineering as It Should Be - Chapter 2: Document Security
This ebook covers basic tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Chapter 2 covers cybersecurity and answers the question: How do you secure your files and documents? Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close