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
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
RE: Conversion of Tree from Chineese to English
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
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
Deepak Gupta
SW2009 SP3.0
SW2007 SP5.0
RE: Conversion of Tree from Chineese to English
Deepak Gupta
SW2009 SP3.0
SW2007 SP5.0
RE: Conversion of Tree from Chineese to English
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
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
Please feel free to ask any questions if you have ones.
Artem Taturevich, CSWP
Software and Design Engineer
AMCBridge LLC
www.amcbridge.com
RE: Conversion of Tree from Chineese to English
Deepak Gupta
SW2009 SP3.0
SW2007 SP5.0
RE: Conversion of Tree from Chineese to English
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
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
Thanks a lot.
Deepak Gupta
SW2009 SP3.0
SW2007 SP5.0
MathCAD 14.0
RE: Conversion of Tree from Chineese to English
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
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