API - SetMaterialPropertyName2

Discussion in 'SolidWorks' started by Mark Reimer, Oct 12, 2005.

  1. Mark Reimer

    Mark Reimer Guest

    I am using SetMaterialPropertyName2 to set the material name in a part,
    but I don't want to use the colors and textures that are defined in the
    material. I want the part to visually stay like it is, but this
    function will change both the color and texture as if I had both the
    "Use Advanced Graphics" and "Use Material Color" options in the "Edit
    Material" PM page checked even though they are not. That would be
    acceptable if I could at least turn them off, but I can't find a way to
    do that. I tried to remember teh current appearance by using Get and
    SetMaterialPropertyValues, but it appears to ignore this once the
    material is set.

    I am using the 2005 API in my program, but have looked at the 2006 API
    help and there does not appear to be anything new there. When I run my
    program in 2006, it has the same behavior as well.

    Has anyone used the SetMaterialPropertyName2 while retaining the
    appearance of the original part?

    Thanks
    --Mark
     
    Mark Reimer, Oct 12, 2005
    #1
  2. Mark Reimer

    Mark Reimer Guest

    I put the function in a macro and created it and ran it in 2005 and
    2006 but I can't get the original appearance of the part back once the
    material propery name is changed. It looks to me like an enhancement
    request will be needed here to add the option of applying visual
    properties or not in the SetMaterialPropertyName2 method, or perhaps it
    is a bug in the program that will not allow visual properties to be
    changed once they are set. Anyway, here is the macro if anyone is
    interested.

    Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim ModelDoc As SldWorks.ModelDoc2
    Dim PartDoc As SldWorks.PartDoc
    Dim vMatProp As Variant

    Set swApp = Application.SldWorks
    Set ModelDoc = swApp.ActiveDoc
    Set PartDoc = ModelDoc

    'Save current material settings
    vMatProp =
    ModelDoc.Extension.GetMaterialPropertyValues(swAllConfiguration, "")

    'Apply material from Material database
    PartDoc.SetMaterialPropertyName2 "", "solidworks materials.sldmat",
    "Ductile Iron"

    'Attempts to restore original state
    ModelDoc.Extension.RemoveTexture2 ""
    ModelDoc.Extension.SetTexture "", Nothing
    ModelDoc.Extension.RemoveMaterialProperty swAllConfiguration, ""
    ModelDoc.Extension.SetMaterialPropertyValues vMatProp,
    swAllConfiguration, ""

    'Rebuild because some restored values go away after a rebuild
    ModelDoc.ForceRebuild3 False
    End Sub
     
    Mark Reimer, Oct 12, 2005
    #2
  3. Mark Reimer

    That70sTick Guest

    I combed through the API help, including
    SetUserPreferenceToggle/...Double/...String calls.

    Nothing.
     
    That70sTick, Oct 12, 2005
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.