More API questions-- hey Corey!

Corey, thanks a bunch for the help yesterday- I got it working.

Two more questions:

1) is there a way to select the last item created? I am using Part.Extension.SelectByID("XY (Front)", "PLANE", 0, 0, 0, False, 0, Nothing) for example, but after I create features I have trouble referencing them. Do I have to do Set line = ... and use line to reference, or is there a "select the last feature" command?

2) Why do I get a "object variable or with block variable not set" error with this (when I debug, it highlights the Construction Geometry line; the line doesn't draw on the screw btw): Part.ClearSelection2 True boolstatus = Part.Extension.SelectByID("XY (Front)", "PLANE", 0, 0, 0, False, 0, Nothing) Part.InsertSketch2 (True) Dim line2 Set line2 = Part.CreateLine2(1, 1, z, 2, 2, z) If IsNull(line2) Then MsgBox ("line2 is null") End If line2.ConstructionGeometry = (True) Part.InsertSketch2 False

Thanks again for any help!

-Mike

Reply to
Mike
Loading thread data ...

use as much as possible functions that return the object they created, such as Set line = Part.CreateLine2(1, 1, z, 2, 2, z) it's much faster than through the selection mechanism, which you should use only when using old APIs which do not return an object. Define a function such as

Function LastSelection() as Object Dim n as integer:n=swapp.SelectionManager.GetSelectedObjectCount if n=0 then exit function Set LastSelection=swapp.SelectionManager(GetSelectedObject(n)) End Function

probably because your line wasn't created and the IsNull test is wrong: IsNull tests if a Variant doesn't contain anything you should use the "Is Nothing" test to check if it contains an invalid object :

If line2 Is Nothing Then MsgBox ("line2 is null")

Select View/Local Variables Window in VBA to check the value of variables while debugging. Just a remark : for many reasons, you'd better define variables explicitely when you know their type. Avoid Variants as much as possible.

Option Explicit Dim line2 As SldWorks.SketchLine

Reply to
Philippe Guglielmetti

Listen to Philippe.

When creating my own apps I try to never select by ID because,

Say you start a model and > > Two more questions:

explicitely

Reply to
Corey Scheich

Could you give an example of this? I have been unsuccessful at selecting using anything other than SelectByID. If possible I'd like to see how you select a component in an assembly, but whatever example you have readily available would be greatly appreciated.

Thanks, Ken

Reply to
TinMan

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.