Too many Select Objects and get Object id

Discussion in 'AutoCAD' started by Clarence, Jan 10, 2005.

  1. Clarence

    Clarence Guest

    The following is just a chunk of code I am working on for an extensive lisp routine. I want to get an object with ssget. Next I want to scale that object. Now my problem: I want to remove one prompt for selecting objects and still get the object id.

    I wanted to remove the entsel, which I have already replaced with entlast. I started commenting out what I thought wasn't needed any longer. But I can't figure out how to get the entity data now.

    (defun c:pickobj ()
    (alert "Select Polyline for Area Field <only 1 object please>:")
    (setq fieldobj (ssget))
    (or
    (if
    (= objquant "0")
    (setq scalobj "1")
    )
    (if
    (= objquant "1")
    (setq scalobj ".5")
    )
    (if
    (= objquant "2")
    (setq scalobj "10")
    ))
    (command "scale" fieldobj "0,0,0" scalobj)
    ;;; (alert "Select Polyline for Area Field")
    ;;; (setvar "errno" 0)
    ;;; (while
    ;;; (and
    ;;; (not ent)
    ;;; (/= (getvar "errno") 52)
    ;;; )
    (setq ent (entlast))
    ;)
    (if ent
    (progn
    (setq ent (vlax-ename->vla-object (car ent)))
    (objmtxt)
    )
    )
    (princ)
    )

    next chunk of code contains:

    (setq objidlwpoly (vla-get-objectid ent))



    thank you for any comments or suggestions!
     
    Clarence, Jan 10, 2005
    #1
  2. Clarence

    T.Willey Guest

    How many objects do you select with the ssget? You can scale the whole group, but then when you want the entity data of one object, you could do (entget (ssname fieldobj 0)). This will grab the first entity in the selection set fieldobj.
    Your (setq ent (entlast)) is grabbing the last entity added to the drawing database, but I don't see that you are controlling the inserting of that entity. But if you get the right entity right now, then just do and (entget ent).

    It might be more helpful if we know what you are trying to do with the routine in this part.

    Hope that helps a little.

    Tim
     
    T.Willey, Jan 10, 2005
    #2
  3. Clarence

    Clarence Guest

    I want to select just one object, scale it, get the area of it using field, and then scale it back to the original size. In this portion of code that I provided, I am getting the object, then scaling it, and finally getting the object id to pass thru to the field command.

    Can ssget be programmed to allow the selecting of just one object only?

    FYI - I can't do different calculations sq. ft. to sq. yds. and etc. So I've decided to adjust the size of the object to get my calculations. I think I might've found a hole in "the wall" that I had run into last week. :)

    I'll give your suggestions a try and let you know how it goes.....

    Thanks again for your help Tim.
     
    Clarence, Jan 11, 2005
    #3
  4. Clarence

    T.Willey Guest

    Happy to help, and yes, you can make ssget only select once.

    (setq fieldobj (ssget ":S"))

    The :S is for single select, but if you miss, then you miss, so you might want to do a while or something so that you know you have something selected.

    Just a thought.
    Tim

    ps. Hope your hole works out for ya.
     
    T.Willey, Jan 11, 2005
    #4
  5. Could you just get the area of the object, and then multiply it by the
    square of the scale factor you were going to use? That would spare you the
    trouble of scaling the object and scaling it back.
     
    Kent Cooper, AIA, Jan 11, 2005
    #5
  6. Clarence

    Clarence Guest

    I'm running = A2K5

    Sorry Kent but that is not possible. I am using fields to get the area. Autodesk doesn't define the field expressions anywhere, and the options provided are very limited in use. And calculations cannot be passed to a field. There is a field that gets sq. ft. only, so I'm scaling the object according to the math to get the appropriate quantity.

    BTW - instead of scaling back, I copied the object to a different layer, and then scaled that object and I'm going to erase it and it's layer before the command is done.

    Thanks for the input!
     
    Clarence, Jan 11, 2005
    #6
  7. Clarence

    Clarence Guest

    I added the single selection, thanks for the tip.

    But I'm still having troubles getting the object id without using entsel......

    here's the code as of right now:

    (defun c:pickobj ()
    (alert
    "Select Polyline for Area Field <only 1 object please>:"
    )
    (setvar "errno" 0)
    (while
    (and
    (not bndobj)
    (/= (getvar "errno") 52)
    )
    (setq bndobj (ssget ":S"))
    )
    (command "-layer" "m" "temp" "" "")
    (command "copy" bndobj "" "0,0,0" "0,0,0")
    (setq fieldobj (ssget "L"))
    (command "chprop" fieldobj "" "LA" "temp" "" "")
    (or
    (if
    (= objquant "SF")
    (setq scalobj "1")
    )
    (if
    (= objquant "SY")
    (setq scalobj ".5")
    )
    (if
    (= objquant "AC")
    (setq scalobj "10")
    ))
    (setq obj2scal (ssget "L"))
    (setq nuscal (STRCAT scalobj))
    (command "scale" obj2scal "" "0,0,0" nuscal)
    (setq ent (ssget "L"))
    ;;; (alert "Select Polyline for Area Field")
    ;;; (setvar "errno" 0)
    ;;; (while
    ;;; (and
    ;;; (not ent)
    ;;; (/= (getvar "errno") 52)
    ;;; )
    ;;; (setq ent (entlast))
    (entget ent)
    ;)
    (if ent
    (progn
    (setq ent (vlax-ename->vla-object (car ent)))
    (objmtxt)
    )
    )
    (princ)
    )
    (defun objmtxt ()
    (setq objidlwpoly (vla-get-objectid ent))
    (setq lwpolyobj (itoa objidlwpoly))
    (command "luprec" (strcat decimals))
    (setq atfield
    (strcat
    "%<\\AcObjProp Object(%<\\_ObjId "
    lwpolyobj ">%).Area \\f \"%"
    thisqty " "
    objquant "\">%"
    )
    )
    this is not all of the code......

    summary of this portion of code:
    1. get the object
    2. make a copy and put it on a different layer
    3. set scale from dialog box choices and scale the object
    4. get the object id to pass down to the field <problem>
     
    Clarence, Jan 11, 2005
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.