roldy
Aerospace
- Sep 3, 2012
- 54
I'm stuck on a coding project for work. The task is to create cylinders along each segment of a line in the 3d Sketch. Each body will be colored based off of some values in a table, which I don't have right now, so I am instead trying to assign a color.
First problem is that I can't get the InsertStructuralWeldment to create the weldment. I can't see what I am doing wrong with this. I tried adapting the code from the help file.
Second problem is assigning a color to a body. I can see what the materialpropertiesvalues2 of a body are but I can't figure out how to assign a color to this body. I created an array of values for R, G, B, Ambient, Diffuse, Specularity, Shininess, Transparency, and Emission. I then tried to use swBody.MaterialPropertyValues = materialProp, where materialProp is my array of property values. I did a graphics redraw and the body color didn't change.
In the zip file, I included the Excel table from which the macro reads the starting point of the first line segment and then creates successive lines based off the angle and the length in each row of the table. I've also included the custom weldment profile I will be using which the macro calls for. The reason why I'm using a weldment to create these solids is because it allows me to create all the solids in one pass instead of having to create a plane on each endpoint of a line segment and then extruded my profile up to the next endpoint.
To run, extract the "testing" folder to C: and open up the empty "test.SLDPRT" file. Make sure that Excel is not open when running the macro.
I'm using SolidWorks 2021 SP3.
First problem is that I can't get the InsertStructuralWeldment to create the weldment. I can't see what I am doing wrong with this. I tried adapting the code from the help file.
Second problem is assigning a color to a body. I can see what the materialpropertiesvalues2 of a body are but I can't figure out how to assign a color to this body. I created an array of values for R, G, B, Ambient, Diffuse, Specularity, Shininess, Transparency, and Emission. I then tried to use swBody.MaterialPropertyValues = materialProp, where materialProp is my array of property values. I did a graphics redraw and the body color didn't change.
In the zip file, I included the Excel table from which the macro reads the starting point of the first line segment and then creates successive lines based off the angle and the length in each row of the table. I've also included the custom weldment profile I will be using which the macro calls for. The reason why I'm using a weldment to create these solids is because it allows me to create all the solids in one pass instead of having to create a plane on each endpoint of a line segment and then extruded my profile up to the next endpoint.
To run, extract the "testing" folder to C: and open up the empty "test.SLDPRT" file. Make sure that Excel is not open when running the macro.
I'm using SolidWorks 2021 SP3.