What's new

Drawing BSplines from code

eneyer

Member
Drawing BSplines from code

I have everything in order in my code for creating sketch objects/lines/extruding.

My problem arrises with efficiency. I am importing data from some of our design software and I have roughly 1500 lines to draw. As you know, 1500 API calls just drags on (takes a couple minutes to import).

Although it does work, it's very slow. So I was looking into the BSpline function. I want to just add an array of lines without alot of work. The documentation doesn't touch much on this subject. It's easy to do in the interface...

Thanks in advance.
-Eric
 

shubhab

Member


Eric,

I suppose you meant, you want to add an array of BSplines.

I have attached a very simple VB Sample that adds one BSpline. If you need to sketch several such BSplines, you will have to have different Control Points, weights, knots etc and then finally include the IADDSketchFigures.AddBspline method with those various parameters in a loop.

I hope this answers your question. Let me know if you need more clarification.

Thanks,
Shubha,
Alibre, Inc.
 

Attachments

  • BSpline.zip
    3 KB · Views: 12

eneyer

Member


I did mean an array of lines. My problem is that I am calling the line API call for 1440 line segments. As you can imagine, that is VERY innefficient. So the array of lines function I was talking about doesnt exist (as of yet).

I did look at the documentation for the bspline function and was successful at calling a simple version of it, but I don't know what knot vectors are or weights for that matter... It was just my last hope so models don't take 5 minutes to import...

The truth is, the BSpline function is not what I want, but it might be a good enough approximation due to the fact that I have so many points.
 

shubhab

Member


I see what you say. I am sorry, I misunderstood your previous question as array of BSplines, since you were interested in knowing about BSplines.
Did you try sketching lines in a loop(looping 1440 times) and see if it took less amount of time as that for importing a file?
 

eneyer

Member


yeah. I looped 1440 times. As far as I know, I can't import a file from code. I did try it. It was much faster
 

shubhab

Member


Can you post your enhancement request (An Array function as you mentioned earlier) under 'Enhancements' Section in 'Drawing API Functionality'?
 

shubhab

Member


Hi Eric,

You had question regarding the Helix Interface in the enhancement request.
Currently for a Helical Feature, for the Axis field, you will need to have a Reference Line(which is a Reference Sketch figure) in the same Sketch as the Circle, i.e. both the Circle and the reference Line have to be part of one single Sketch.
The current Design will let you pick only the Reference Line for the axis field and not the Reference axis.

Thanks,
Shubha
Alibre, Inc.
 

eneyer

Member


OK. I got that working, but actually what I need is a helix rotating around an axis in a different plane. I tried it in a 3D Sketch to no avail...

Well if there is a way to do it, it still wont help me unless I have an API call for it...
 

shubhab

Member


How about trying the Sweep Feature for this? The Path Objects can be 3D sketches.
But, as you said, this can't be done via our API though and the above approach would be lot more difficult. Although we have the 3DSketch Interface in our API, you can at present only query for 3D Sketches. You will not be able to add a 3D Sketch via API.
 

alexfranke

Senior Member


Hi eneyer,

If you were loooking to draw a polyline (set of lines connected end-to-end), you can in fact do this with the b-spline method in one API call, and it's pretty quick. The polyline will be exact -- not just an approximation. I have a simple example of the output on my Point Import Wizard tutorial page (about half way down) at http://plans.thefrankes.com/Tutorials/P ... ortWizard/

There's also a brief description of knots and order.

To draw the polyline, use the all the points that describe the polyline (the endpoints and the "joint" points) as the control points, and set the b-spline order to 2.

To help clear up the terminology, the order means that the curve is made up of piecewise polynomial segments of degree: order - 1. So, where order == 2, the segments will be degree 1, which is a straight line.

The knot vector is simply a set of non-decreasing numbers that define how the curve is affected by the control points. (where order > 2) The actual values of the numbers don't matter, it's how those values relate to eachother that matters. In math, it's common to make them range from zero to 1, so you might see 0, 0.25, 0.5, 0.75, 1, which means the curve is affected equally along its length. You can just as easily do 1, 2, 3, 4, 5 which will produce the same curve (these values are still evenly spaced). Knot vectors often start and und with repeating numbers (like 0,0,0,1,2,3...) which, depending upon the order, can "pin" (or clamp) the start of the line to the starting control point. For your polyline, use a uniform knot vector and clamp the endpoints.

The weights indicate how much each control point will affect its knots, so a control point with a higher weight will cause the curve to pull more toward that point. Set all the weights to 1 for the polyline.

Hope this helps...
-Alex
 

eneyer

Member


Thank you so much...

This is the reason why I originally posted this as a B-Spline thread. I was just going to use existing APIs and try to emulate straight line segments. The research was taking too much time. Thanks for explaining it for me.

I guess I could have expected nothing less from the creator of the famed Point Input Wizard!

Haha. Thanks again.
 
Top