Hello,
A macro I'm writing needs to split a solid body into two, assign a heavier material to one of these bodies, and an ideally, a weightless material to the other body. By "weightless" I mean that it's density should be 0. That body must be visible, but by definition, it must not affect the Center of Mass of the model.
I've looked through the Material Database that comes with SolidWorks, and I was unable to find any materials that have a density of 0. The material Air is pretty light, but not the 0 kg / m^3 that I need.
Theoretically, I could write a function in my macro to create a custom material - just copy some other material, and change it's density to 0, and then assign this material to the body - but I would like to avoid this if possible. I wouldn't even know how to do that.
Are there any other options to make one of the two bodies in my model visible, yet weightless?
SolidworksApi macros
Hello J. R.,.. you could make the solid body a surface.. just delete a small face which is not seen or create a very small split on a face.. and delete it..
You could turn the body into a surface body. Then by definition it would have no volume or mass.
The fastest way to make a solid into a surface is by using Delete Face to remove one of the faces without healing. If you don't want to have a missing face on your solid, copy the face before deleting using Offset (with zero value) then sew together after deleting original face.
Dang it, Paul! Don't submit posts while I'm typing
Same idea here, but there is an api call sadly missing from the UI IMHO
2016 SOLIDWORKS API Help - CreateSurfaceFeatureFromBody Method (IPartDoc)
or 2016 SOLIDWORKS API Help - CreateFeatureFromBody3 Method (IPartDoc)
You can actually edit the solidworks sldmat file (solidworks material database) and add a new material to it. It has an xml marked schema so it's pretty easy to edit.
Thank you, but since the macro will have to re-build the model thousands of times, I want to keep the extra features to minimum to save on rebuild time...
Thank you, but since the macro will have to re-build the model thousands of times, I want to keep the extra features to minimum to save on rebuild time...
I suppose that's possible, but is there no simpler way?
Why don't you just get mass properties for a single body instead of the whole part? You wouldn't even need to monkey about with densities, then. It can all be done with math.
First time I hear about it... I often wondered if that is possible. Would you care to elaborate? How do I get mass of a selected body?
2017 SOLIDWORKS API Help - GetMassProperties Method (IBody2)
You can change the material properties body by body. In addition, you can override the mass properties of each body separately. Nevermind....you can't do override individual bodies....but you can essentially make a body have 0 mass by assigning it a material with 0 mass. (If you want to use steel as the material and still give it 0 mass, then just make a copy of steel in your material database and then give it the copy a density of 0, then assign that to the 2nd body).
Change the material to Air.
..or,.. aether?
- That's a floating comment - I like my model with a little weight, it's hard to do any pushing against weightless matter, and that would matter, batter batter slap slap
Hello,
The last time I tried to create a zero density material, SW wouldn't let me enter zero.
The density had to be 0.00000001 (or whatever the max decimal places were).
Cheers,
Kevin
When it comes to body creation. Thousands of rebuilds isn't a big deal. The time it takes to create the body is barely recordable. I know this for a fact as my addin creates thousands of bodies per rebuild and it barely registers a second on the body creation portion.
Rebuild is exponentially slower with the addition of additional faces and edges in my experience.
That's what I do, but air still has some density. I need it to be 0 or something like 0.00000000001.
How can I do this solely through macro? I mean, creating a new material like you described, and setting it's density to 0? I assume it could be done by copying a prepared .sldmat file to material library directory, but that can cause all kinds of issues with file permissions (especially in Windows 10), so I'd rather do it from inside SolidWorks.
If only we had the option of setting selective bodies in a multi-body part as envelopes...
Never mind my last question. I solved it this way: creating a txt file through the macro, located at the same directory as the macro itself, then rename it to .sldmat, and finally, referencing the needed body to that .sldmat file. That file only has one material "weightless", which has the lowest possible density. Here's the code:
<p>Sub createMaterialFile()</p><p> Dim fso As Object</p><p> Dim myFile As Object</p><p> Dim file1 As String</p><p> Dim file2 As String</p><p> </p><p> file1 = swApp.GetCurrentMacroPathName</p><p> file1 = Left(file1, Len(file1) - 30)</p><p> file2 = file1 & "Hydrostatics Calculator Materials.txt"</p><p> </p><p> Set fso = CreateObject("Scripting.FileSystemObject")</p><p> </p><p> If Not fso.fileExists(file1 & "Hydrostatics Calculator Materials.sldmat") Then</p><p> Set myFile = fso.CreateTextFile(file2)</p><p> </p><p> myFile.WriteLine "<?xml version=""1.0""?>"</p><p><span> myFile.WriteLine "<mstns:materials xmlns:mstns=""</span><a class="jive-link-external-small" href="https://forum.solidworks.com/external-link.jspa?url=http%3A%2F%2Fwww.solidworks.com%2Fsldmaterials" rel="nofollow" target="_blank" data-community-id="1">http://www.solidworks.com/sldmaterials</a><span>"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:sldcolorswatch=""</span><a class="jive-link-external-small" href="https://forum.solidworks.com/external-link.jspa?url=http%3A%2F%2Fwww.solidworks.com%2Fsldcolorswatch" rel="nofollow" target="_blank" data-community-id="1">http://www.solidworks.com/sldcolorswatch</a><span>"" xmlns:xsi=""</span><a class="jive-link-external-small" href="https://forum.solidworks.com/external-link.jspa?url=http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance" rel="nofollow" target="_blank" data-community-id="1">http://www.w3.org/2001/XMLSchema-instance</a><span>"" version=""2008.03"">"</span></p><p> myFile.WriteLine "<curves id=""curve0"">"</p><p> myFile.WriteLine vbTab & vbTab & "<point x=""1.0"" y=""1.0""/>"</p><p> myFile.WriteLine vbTab & vbTab & "<point x=""2.0"" y=""1.0""/>"</p><p> myFile.WriteLine vbTab & vbTab & "<point x=""3.0"" y=""1.0""/>"</p><p> myFile.WriteLine vbTab & "</curves>"</p><p> myFile.WriteLine vbTab & "<classification name=""Hydrostatics Calculator Materials"">"</p><p> myFile.WriteLine vbTab & vbTab & "<material name=""Weightless"" matid=""79"" failurecriteria=""4"" envdata=""1"" description="""" propertysource="""" appdata="""">"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & "<shaders>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & vbTab & "<pwshader2 name=""air"" isNewShader=""1"" path=""\organic\sky\air.p2m""/>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & vbTab & "<pwshader name=""air""/>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & vbTab & "<cgshader2 name=""defaultplastic""/>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & "</shaders>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & "<swatchcolor RGB=""d7ccff"">"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & vbTab & "<sldcolorswatch:Optical Ambient=""1.000000"" Transparency=""0.900000"" Diffuse=""1.000000"" Specularity=""1.000000"" Shininess=""0.200000"" Emission=""0.300000""/>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & "</swatchcolor>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & "<xhatch name=""Stars"" angle=""0.0"" scale=""1.0""/>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & "<sustainability linkId=""76"" dbName=""SOLIDWORKS Materials""/>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & "<physicalproperties>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & vbTab & "<NUXY displayname=""Poisson's Ratio"" value=""0.000000000000000"" usepropertycurve=""0""/>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & vbTab & "<DENS displayname=""Mass Density"" value=""0.000000000000001"" usepropertycurve=""0""/>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & vbTab & "<KX displayname=""Thermal Conductivity"" value=""0.027"" usepropertycurve=""0""/>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & vbTab & "<C displayname=""Specific Heat"" value=""1000"" usepropertycurve=""0""/>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & "</physicalproperties>"</p><p> myFile.WriteLine vbTab & vbTab & vbTab & "<custom/>"</p><p> myFile.WriteLine vbTab & vbTab & "</material>"</p><p> myFile.WriteLine vbTab & "</classification>"</p><p> myFile.WriteLine "</mstns:materials>"</p><p> </p><p> myFile.Close</p><p> Name file1 & "Hydrostatics Calculator Materials.txt" As file1 & "Hydrostatics Calculator Materials.sldmat"</p><p> End If</p><p>End Sub</p>And the sub that assigns this material to a body:
<p>Sub AssignMaterials()</p><p> Dim file1 As String</p><p> file1 = swApp.GetCurrentMacroPathName</p><p> file1 = Left(file1, Len(file1) - 30)</p><p> </p><p> file1 = file1 & "Hydrostatics Calculator Materials.sldmat"</p><p> </p><p> Debug.Print file1</p><p></p><p> swModel.SetMaterialPropertyName2 "", "", ""</p><p> boolstatus = swModel.Extension.SelectByID2("Emerged", "SOLIDBODY", 0, 0, 0, False, 0, Nothing, 0)</p><p> swModel.SetMaterialPropertyName2 swApp.GetActiveConfigurationName(swModel.GetPathName), file1, "Weightless"</p><p>End Sub</p>Maybe not the most elegant solution, but it seems to work!
Hi J.R.
If you need the exact COG for a given setup why not add Center of Mass Reference Points & custom mass properties. If you want the mass & location itself then simply hide all other bodies and uncheck "include hidden bodies" in the mass property dialog.
See Get and Override Mass Properties Example (VBA) in API help.