Hi,
I am trying to set the color of a selected feature, but when I try to call ISetMaterialPropertyValues2 I get the error message: "Wrong number of arguments or invalid property assigned. Can anyone tell me what I am doing wrong?
The problem is probably somewhere with the lines in main():
Set mySelection = swModel.SelectionManager.GetSelectedObject6(1, 0)
boolstatus = mySelection.ISetMaterialPropertyValues2(vMatProps, swThisConfiguration, 1, Nothing)
The macro code is below. (You can ignore the whole DrawPlate subroutine since that works with no problems) I first create a new part document before I run this macro.
I've tried many different things with no success. Thanks in advance for any help!
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim mySelection As Object
Sub DrawPlate(plateNum As Integer, _
x1 As Double, y1 As Double, z1 As Double, _
x2 As Double, y2 As Double, z2 As Double, _
x3 As Double, y3 As Double, z3 As Double, _
x4 As Double, y4 As Double, z4 As Double)
Dim skSegment As Object
Dim myRefPlane As Object
Dim myFeature As Object
Part.SketchManager.Insert3DSketch True
Set skSegment = Part.SketchManager.CreateLine(x1, y1, z1, x2, y2, z2)
Set skSegment = Part.SketchManager.CreateLine(x2, y2, z2, x4, y4, z4)
Set skSegment = Part.SketchManager.CreateLine(x4, y4, z4, x3, y3, z3)
Set skSegment = Part.SketchManager.CreateLine(x3, y3, z3, x1, y1, z1)
Part.ClearSelection2 True
Part.SketchManager.InsertSketch True
boolstatus = Part.Extension.SelectByID2("Line4@3DSketch" + CStr(plateNum), "EXTSKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line3@3DSketch" + CStr(plateNum), "EXTSKETCHSEGMENT", 0, 0, 0, True, 1, Nothing, 0)
Set myRefPlane = Part.FeatureManager.InsertRefPlane(4, 0, 4, 0, 0, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("3DSketch" + CStr(plateNum), "SKETCH", 0, 0, 0, True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Plane" + CStr(plateNum), "PLANE", 0, 0, 0, True, 16, Nothing, 0)
Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.0001, 0.0001, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, False, True, True, 0, 0, False)
Part.SelectionManager.EnableContourSelection = False
Part.ClearSelection2 True
End Sub
Sub main()
Set swApp = _
Application.SldWorks
Set swModel = swApp.ActiveDoc
Set Part = swApp.ActiveDoc
Dim vMatProps As Variant
boolstatus = Part.Extension.SetUserPreferenceInteger(SwConst.swUserPreferenceIntegerValue_e.swUnitSystem, 0, SwConst.swUnitSystem_e.swUnitSystem_MKS)
Call DrawPlate(1, 0.0334544, 0.069138, 0, -0.0334544, 0.069138, 0, 0.0334544, -0.069138, 0, -0.0334544, -0.069138, 0)
vMatProps = Part.MaterialPropertyValues
vMatProps(0) = 1
vMatProps(1) = 0.9098
vMatProps(2) = 0.6196
boolstatus = Part.Extension.SelectByID2("Boss-Extrude1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
Set mySelection = swModel.SelectionManager.GetSelectedObject6(1, 0)
boolstatus = mySelection.ISetMaterialPropertyValues2(vMatProps, swThisConfiguration, 1, Nothing)
Part.ViewZoomtofit2
End Sub
SolidworksApi macros