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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
"Mike" wrote:

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
--
Philippe Guglielmetti - www.dynabits.com



Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Listen to Philippe.
When creating my own apps I try to never select by ID because,
Say you start a model and open a sketch. then decide not to use it. Now you run your macro. Your macro creates a sketch. You would have assumed in your macro that the sketch is named Sketch1 but now it is Sketch2. then your macro shuts down and yells at you because there was nothing selected. When you do the same scenerio and select using the actual object that was passed when your sketch was created every thing is all happy again.
Corey

such
use
explicitely
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.