Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Feature creation in API

Anonymous

Feature creation in API

Anonymous
No aplicable

Hi,

 

Very new to using the API in FeatureCAM. I tried creating Features with dimensions such as Pocket, Hole and they work fine. I'm figuring out how to create Features using curves. The API help mentions that curves must be defined as Variant. What does that mean and how do I define the curves? 

 

 

Here's a very simple code that I tired, but it doesn't work for AddPocket. If I give the exact name of the curve in " " - it works.

For e.g. doc.Features.AddPocket("curve12', 6) -- This works. 

But the curve names will differ and also there can be multiple curves in a project. So how do I define it in the macro?

 

 

Sub Main

	Dim doc As FMDocument
	Set doc = Application.ActiveDocument

	doc.Features.AddRectPocket(100, 50, 5)

	doc.Features.AddPocket("???", 6)

End Sub

 

0 Me gusta
Responder
Soluciones aceptadas (1)
692 Vistas
4 Respuestas
Respuestas (4)

Anonymous
No aplicable

A Variant type means it can be one thing or another (typically two choices, sometimes N!) 

In this case, you can either pass the name of a curve, or the curve itself.  For instance, if you make a curve like:

Dim resultCurve As IFMCurve

...

Set resultCurve = curvePtList.AddCurveFromPtList(False)

' then you can pass the IFMCurve to the pocket

doc.Features.AddPocket(resultCurve, ...)

' or you can do as you do above, and pass the string name of the curve, as in,

doc.Features.AddPocket(resultCurve.Name, ...

 

Anonymous
No aplicable

Hi @Anonymous,

 

Thanks a lot for the information. I tried your method and it works great. But this creates a curve based on Point list pattern. 

What if I need to pass some of the existent curves in the document? (for e.g. in the below pic, I've got 3 curves in the document already and I need to create a Pocket feature from only 2 of those). Can these be passed by names or selection?

 

I tried using multiple names - doc.Features.AddPocket("curve1, curve3", ... - but that doesn't work. It only takes one curve name at a time.

 

cc.png

 

0 Me gusta

Anonymous
No aplicable
Solución aceptada

if you wish to create two pockets out of two curves, call it twice - once for each curve.  If you wish to create one pocket from two curves, there are different variations for the VARIANT that are also useful.

you passed it one string (which it thought was the one name of one curve) - the variant that works in that case is a string array. E.g.,

   Dim crvArray(2) As String
   crvArray(1) = "crv1"
   crvArray(2) = "crv4"
   Dim fmdc As FMDocument
   Set fmdc = Application.ActiveDocument
   fmdc.Features.AddPocket( crvArray, 1 )

 

you could also make a pocket from whatever curve(s) is/are selected by saying:

   fmdc.Features.AddPocket( fmdc.Selected , 1 )  ' get the selected set and pass it to AddPocket.   

if something nonsensical is selected, then addPocket should return Nothing, but you can select N curves and it will make a pocket out of them.

 

Anonymous
No aplicable

Hi @Anonymous

 

Very useful information. I tried what you mentioned and it works great!

 

Thank you for all your help.

0 Me gusta