I tried to record a macro for changing the part appearance. However, the code does not show anything regarding the change. Does anyone have any example (e.g. change RGB and change the transparent)
Thank
I tried to record a macro for changing the part appearance. However, the code does not show anything regarding the change. Does anyone have any example (e.g. change RGB and change the transparent)
Thank
Sure, see the code - just set the number of RGB
Set swApp = Application.SldWorks
Set swModelDoc = swApp.ActiveDoc
Set swPart = swModelDoc
vMatProps = swPart.MaterialPropertyValues
'Define the RGB values (1 = RGB value 255)
vMatProps(0) = 154 / 255 'R
vMatProps(1) = 155 / 255 'G
vMatProps(2) = 156 / 255 'B
swPart.MaterialPropertyValues = vMatProps
swModelDoc.GraphicsRedraw2
swModelDoc.Save3 swSaveAsOptions_Silent, nErrors, nWarnings
Hello, I'm having trouble with the last line:
swModelDoc.Save3 swSaveAsOptions_Silent, nErrors, nWarnings
and I think without it doesn't save the appearance settings. While it does change the appearance of the part, if you go into the appearance values, nothing is different.
Kyle Hofmeister wrote:
Hello, I'm having trouble with the last line:
swModelDoc.Save3 swSaveAsOptions_Silent, nErrors, nWarnings
and I think without it doesn't save the appearance settings. While it does change the appearance of the part, if you go into the appearance values, nothing is different.
What's the trouble?
Hi Christian,
I get a
Run-time error '13':
Type mismatch
The debugger highlights that line as the problem.
Sure! Just so you know whats going on, the Macro takes 2 3d sketches and lofts then together to form a box. Then the appearance is changed at the bottom. Its just a rough draft for now so it looks sloppy but you get the point.
Thanks for your help
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swSaveAsOptions_Silent As Integer
Dim Errors As Integer
Dim Warnings As Integer
Dim Save As Boolean
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swModelDoc = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = Part.Extension.SelectByID2("Part Box Top", "SKETCH", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Part Box Bottom", "SKETCH", 0, 0, 0, True, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Part Box Top", "SKETCH", 0.2413, 6.35000000000003E-03, 0.25654, False, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Part Box Bottom", "SKETCH", 0.2413, 6.35000000000003E-03, 0.20066, True, 1, Nothing, 0)
Part.FeatureManager.InsertProtrusionBlend False, True, False, 1, 0, 0, 1, 1, True, True, False, 0, 0, 0, False, True, True
boolstatus = Part.Extension.SelectByID2("Stock", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.SelectedFeatureProperties(0, 0, 0, 0, 0, 0, 0, 1, 0, "Stock")
vMatProps = Part.MaterialPropertyValues
'Define the RGB values (1 = RGB value 255)
vMatProps(0) = 39 / 255
vMatProps(1) = 158 / 255
vMatProps(2) = 255 / 255
vMatProps(7) = 0.65
Part.MaterialPropertyValues = vMatProps
swModelDoc.GraphicsRedraw2
swModelDoc.Save3 swSaveAsOptions_Silent, Errors, Warnings
Part.ClearSelection2 True
End Sub
I changed some of the lines. Try and let me know
'Dim swApp As Object
Dim swApp As SldWorks.SldWorks ' Christian
Dim part As Object
Dim swModelDoc As SldWorks.ModelDoc2 ' Christian
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swSaveAsOptions_Silent As Integer
Dim Errors As Long ' Integer Christian
Dim Warnings As Long ' Integer Christian
Dim Save As Boolean
Sub main()
Set swApp = Application.SldWorks
'Set part = swApp.ActiveDoc
Set swModelDoc = swApp.ActiveDoc
Set part = swModelDoc ' Christian
Set myModelView = part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = part.Extension.SelectByID2("Part Box Top", "SKETCH", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = part.Extension.SelectByID2("Part Box Bottom", "SKETCH", 0, 0, 0, True, 0, Nothing, 0)
part.ClearSelection2 True
boolstatus = part.Extension.SelectByID2("Part Box Top", "SKETCH", 0.2413, 6.35000000000003E-03, 0.25654, False, 1, Nothing, 0)
boolstatus = part.Extension.SelectByID2("Part Box Bottom", "SKETCH", 0.2413, 6.35000000000003E-03, 0.20066, True, 1, Nothing, 0)
part.FeatureManager.InsertProtrusionBlend False, True, False, 1, 0, 0, 1, 1, True, True, False, 0, 0, 0, False, True, True
boolstatus = part.Extension.SelectByID2("Stock", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = part.SelectedFeatureProperties(0, 0, 0, 0, 0, 0, 0, 1, 0, "Stock")
vMatProps = part.MaterialPropertyValues
'Define the RGB values (1 = RGB value 255)
vMatProps(0) = 39 / 255
vMatProps(1) = 158 / 255
vMatProps(2) = 255 / 255
vMatProps(7) = 0.65
part.MaterialPropertyValues = vMatProps
swModelDoc.GraphicsRedraw2
swModelDoc.Save3 swSaveAsOptions_Silent, Errors, Warnings
part.ClearSelection2 True
End Sub
Sure, see the code - just set the number of RGB