automated tangent lines

I'm trying to make a macro that takes the two selected arcs and creates a line thats tangent to both, and the start and end points are coincident to the arcs.  I'm having some trouble with the getselectedobjects(n) property.

     I'm guessing it would work something like this:

          set obj1 = selmgr.getselectedobject5(1)

          set obj2 = selmgr.getselectedobject5(2)

          sksegment = createline( x1,y1,z1,x2,y2,z2 )

          clearselectedobjects

         

          seldata = createselectdata

          obj1.select4(true,seldata)

          sksegment.select4(true,seldata)

          sketchaddconstraints("sgtangent")

         

          clearselectedobjects

         

          obj2.select4(true,seldata)

          sksegment.select4(true,seldata)

          sketchaddconstraints("sgtangent")

          clearselectedobjects

         

          obj1.select4(true,seldata)

          [select start point of line]

          sketchaddconstraints("sgcoincident")

          clearselectedobjects

         

          obj2.select4(true,seldata)

          [select end point of line]

          sketchaddconstraints("sgcoincident")

         

          clearselectedobjects

          end

I can't seem to select the arcs that I saved into obj1 and obj2.  Select4 isn't working after I create the line.

SolidworksApi macros
Answers 5
ST
ST 2013-12-03 Best Answer

Is obj1 defined as a SketchArc or a SketchSegment?

It needs to be a SketchSegment in order to use Select4

DZ
DZ 2013-12-03

I'm not sure.  I just use getselectedobj5 to select it.  I defined it as an object.  Should I define it as a sketchsegment then call getselectedobject5() to save it?

ST
ST 2013-12-03

Yes. Dim obj1 and obj2 as SketchSegment

Alternatively, use another variable (e.g. Dim mySeg as SketchSegment) and set that = obj1

Personally, I would use GetSelectedObjectType3 before using GetSelectedObject5 in order to make sure that the user has definitely selected an arc. Otherwise your program will crash.

By the way, you can use "Nothing" instead of seldata, unless you want to add a mark to the selections.

DZ
DZ 2013-12-03

oh!  I didn't know you can use "nothing" for seldata.  Thanks.  I'll try getselectedobjecttype3 when I get off of work.

DZ
DZ 2013-12-03

I'm curious to know if I can add an icon for this macro in the "add relations" tab (tools-relations-add).  I select the two arcs and my icon pops up.  I click it, a line is created and I can select 2 more arcs.  I'm drawing a path for about 250 rollers and it's tedious to constantly do this: "l", click arc1, click arc2, esc, "l", click arc1, click arc2, esc (damn not tangent), click line, ctrl-click arc, tangent, esc, click point, click arc, click coincident, esc, click line, click arc2, tangent, click pt2, click arc2, coincident....You see how this can get tedious.  Took me three hours to do it by hand