This is a crosspost from 3DSwym but lately I feel that I cannot get any help there anymore. This forum seems more appropriate and I appreciate the structure greatly.
I was trying to build a macro that changes the texture angle by 90degrees. This is to visualize the wood grain properly (final goal would be to align the grain with a coordinate system that we put in.
Dim swApp As SldWorks.SldWorks
Dim myModel As SldWorks.ModelDoc2
Dim myPart As SldWorks.PartDoc
Dim myMatVisProps As SldWorks.MaterialVisualPropertiesData
Dim configName As String, databaseName As String
Dim orgAngle As Double
Dim longstatus As Long
Set swApp = Application.SldWorks
Set myModel = swApp.ActiveDoc
Set myPart = myModel
Set myMatVisProps = myPart.GetMaterialVisualProperties()
If Not myMatVisProps Is Nothing Then
orgAngle = myMatVisProps.Angle
orgAngle = orgAngle + 1.57#
myMatVisProps.Angle = orgAngle
longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, 2, Nothing)
longstatus the appearance looses the image path and it only shows a blank part without the texture applied.
Any idea why this happens? (I’m on SolidWorks 2017)
Any idea how to solve this?
Thank you for creating a forum that has a great structure and gathers the most famous programmers regarding SolidWorks.
Were you able to solve this issue @lauritz ?
Perhaps refreshing the graphics or rebuilding solve the issue, have you tried that?
Hey @AmenJlili , I was not able to resolve this. I did not have the time to properly test this further, but I do have some ideas.
To solve the missing image file path I can:
- store the initial image file path
- insert it after changing everything else
To solve the issue of adjusting the mapping to the grain visually:
- add axis to the coordinate system that is defined for CNC
- change mapping style to projection
- use the created grain axis as a selected reference for projection
It is not high priority for us currently though. Maybe next week I can find some time.
Edit: Thank you for the follow up!
Edit2: And I think I need to use the IRenderMaterial Interface with this.
Played with it a little bit, but I cannot seem to get a good grasp of how to change the current appearance properly.
Any advice on how to properly use the
.GetMaterials2 Method does not seem to get the appearance of this specific part. What do I have to do to access i.e.
IRenderMaterial.MappingType from this part? The examples are a little cryptic to me (because they always create a rendermaterial first…)
I am not a professional programmer - so please forgive me if I am missing something obvious.