I am looking for a way to create temporary geometry via API, like lines or circles. Can someone point me to some API commands for this?
For example, when I use the evaluate -> measure tool via the user interface and select two vertices, several lines emerge showing their distance (red, green, blue, black). There are also black circles on the two selected vertices. This is the kind of temporary geometry I am looking for.
Note: I do not want to use temporary bodies, as their visible width changes when I zoom in and out. I want the objects to have the same size no matter what zoom level I have.
SolidworksApi macros
I'm about 90% certain you're going to have to go in this direction:
I have not tried this at all, although I'm curious if it will work in VBA.
Josh is right - I don't think you can do this with VBA
This might be done with a dot NET add-in but it'll not be easy
Hi Jana,
Have you tried WireBody interface, the width don't change when you zoom in and out.
Take this exsample for test the solution.
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.PartDoc
Dim swCurve As SldWorks.Curve
Dim trimmed_curve As SldWorks.Curve
Dim swFeature As SldWorks.Feature
Dim swModeler As SldWorks.Modeler
Dim swBody As SldWorks.Body2
Dim nPt(2) As Double
Dim nPte(2) As Double
Dim vPt As Variant
Dim vDir As Variant
Dim retval As Long
Set swApp = CreateObject("SldWorks.Application")
Set swPart = swApp.ActiveDoc
Set swModeler = swApp.GetModeler
nPt(0) = 0
nPt(1) = 0
nPt(2) = 0
vPt = nPt
nPte(0) = 0
nPte(1) = 0
nPte(2) = 0.0000001
vDir = nPte
Set swCurve = swModeler.CreateLine(vPt, vDir)
'
Set trimmed_curve = swCurve.CreateTrimmedCurve2(0, 0, 0, 0, 0, 0.1)
Set swBody = trimmed_curve.CreateWireBody()
'swPart.SetLineStyle "CHAIN"
retval = swBody.Display3(swPart, 255, swTempBodySelectable)
Stop
End Sub
Thanks
Roberto
Hi Roberto,
thanks for the suggestion. I did not use your example but modified it for my case. In my case, I have an assembly document, not a part document. This is what I wrote (in C#):
IModeler modeler = sldWorks.GetModeler(); // sldWorks is the ISldWorks object (not defined in this snippet)
ICurve curve = modeler.CreateLine(new double[] { 0, 0, 0 }, new double[] { 0.01, 0.01, 0.01 });
IBody2 wire = curve.CreateWireBody();
int retval = wire.Display3(sldWorks.ActiveDoc, 256, (int)swTempBodySelectOptions_e.swTempBodySelectOptionNone);
Debug.WriteLine("return value for display: " + retval); // this returns 0 which means "success"
The strange thing is, even though displaying is successful according to the return value, I cannot see the wire at all.
Any ideas what could be wrong?
Hi Jana,
I can't help you in c# becouse I program in VB.Net,
but I see that you lack the piece of code (in vba)
Set trimmed_curve = swCurve.CreateTrimmedCurve2(0, 0, 0, 0, 0, 0.1)
You must trimming the ICurve becouse when you made it, it's with infinity lenght.
I hope you help your application.
Let me know
Roberto
Hi Roberto,
I omitted the trimming because I thought I wouldn't need it - so thanks for the hint about infinte length!
So this time I added the trimming, but still nothing is to be seen...
Have you ever tried drawing a WireBody in an assembly?
Unfortunately it is no help to me if these WireBodies only work in parts.
But thank you for trying to help!
Hi Jana,
My opinion is that you can use a component as a support for your WireBody or create a Vitual component, this is the right way.
The same thing happens if you want to create a temporary body of a component than you're importing into an assembly.
The OpenGL is more difficult to use than wirebody.
Thanks
Roberto