| Author |
Message |
Clarence
Guest
|
Posted:
Tue Jan 11, 2005 4:23 am Post subject:
Too many Select Objects and get Object id |
|
|
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!
|
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Tue Jan 11, 2005 4:38 am Post subject:
Re: Too many Select Objects and get Object id |
|
|
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 |
|
| Back to top |
|
 |
Clarence
Guest
|
Posted:
Tue Jan 11, 2005 8:17 pm Post subject:
Re: Too many Select Objects and get Object id |
|
|
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.
|
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Tue Jan 11, 2005 9:05 pm Post subject:
Re: Too many Select Objects and get Object id |
|
|
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. |
|
| Back to top |
|
 |
Kent Cooper, AIA
Guest
|
Posted:
Tue Jan 11, 2005 9:53 pm Post subject:
Re: Too many Select Objects and get Object id |
|
|
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
"Clarence" wrote...
| Quote: | 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. |
|
|
| Back to top |
|
 |
Clarence
Guest
|
Posted:
Tue Jan 11, 2005 10:40 pm Post subject:
Re: Too many Select Objects and get Object id |
|
|
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! |
|
| Back to top |
|
 |
Clarence
Guest
|
Posted:
Wed Jan 12, 2005 2:54 am Post subject:
Re: Too many Select Objects and get Object id |
|
|
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> |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Wed Jan 12, 2005 3:17 am Post subject:
Re: Too many Select Objects and get Object id |
|
|
If you select with entsel you can still scale that object and change the properties. Why are you set on using ssget?
(setq bndobj (entsel))
(command "_.copy" (car bndobj) "" '(0 0 0) '(0 0 0))
(setq fieldobj (entlast))
(command "_.chprop" fieldobj "" "_LA" "temp" "")
(command "_.scale" fieldobj "" '(0 0 0) nuscal)
Now you have the new entity id as "fieldobj". You don't need to get it again because it is the object id and it will show the changes that has been made to it. Ie. once you change the layer, do and entget on fieldobj and it will show the new layer.
Hope that helps.
Tim |
|
| Back to top |
|
 |
Clarence
Guest
|
Posted:
Wed Jan 12, 2005 3:33 am Post subject:
Re: Too many Select Objects and get Object id |
|
|
honestly, i didn't know i could use entsel as you have shown me.
Thanks Tim!
I'll let you know how this is going tomorrow....... |
|
| Back to top |
|
 |
Clarence
Guest
|
Posted:
Wed Jan 12, 2005 4:01 am Post subject:
Re: Too many Select Objects and get Object id |
|
|
I've added the code that you gave me and it works fine. But I'm still not getting the "object id".
portion before this is what you had given me:
(setq ent (entlast))<<<bad argument type: consp <Entity name:
(if ent
(progn
(setq ent (vlax-ename->vla-object (car ent)))
(objmtxt)
)
)
(princ)
)
(defun objmtxt ()
(setq objidlwpoly (vla-get-objectid ent))<<<gets the object id
(setq lwpolyobj (itoa objidlwpoly))
(command "luprec" (strcat decimals))
(setq atfield
(strcat
"%<\\AcObjProp Object(%<\\_ObjId "
lwpolyobj ">%).Area \\f \"%"
thisqty " "
objquant "\">%"
)
)
I've tried using fieldobj in place of ent, but it still didn't work.
My point is to get the object id of the scaled object tho. |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Wed Jan 12, 2005 4:06 am Post subject:
Re: Too many Select Objects and get Object id |
|
|
(if ent
(progn
(setq ent (vlax-ename->vla-object fieldobj))
(objmtxt)
)
)
When you use (entlast) it just gives you the entity, when you use (entsel) it gives you the entity and a point, so you have to (car (entsel)) to get the entity.
Try this.
Tim |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Wed Jan 12, 2005 4:06 am Post subject:
Re: Too many Select Objects and get Object id |
|
|
not
(if ent
should be
(if fieldobj
Sorry about that.
Tim |
|
| Back to top |
|
 |
Clarence
Guest
|
Posted:
Thu Jan 13, 2005 1:56 am Post subject:
Re: Too many Select Objects and get Object id |
|
|
thanks for all of your help. I finally got this thing to work. But not as you might expect.
I still have to use entsel for it to work properly. it keeps telling me: bad argument type: consp (entity name: blahblahblah) when i try to use entlast or anything else to select the scaled object.
But I also have realized that I have to backpedal a little bit. I have to modify this to scale the original object up and then back down when I'm done. Right now, I have it set to copy the object to a different layer, scale it down, and then delete it. The problem with this, is the fact that fields don't work without the object that they are attached too.
I must've had my head in the clouds or sumtin yesterday! |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Thu Jan 13, 2005 2:08 am Post subject:
Re: Too many Select Objects and get Object id |
|
|
I wonder if you would be able to use the ScaleEntity method of it when it is an vla-object? You could scale the entity up then down real fast that way maybe without notice. Maybe something like.
(setq BsPt (vlax-3d-point '(0 0 0)))
(setq PEnt (entsel "\n Select polyline: "))
(setq PObj (vlax-ename->vla-object (car PEnt)))
(vla-ScaleEntity PObj BsPt nuscal)
(setq PArea (vla-get-Area PObj))
(vla-ScaleEntity PObj BsPt (/ 1 nuscal))
Just thinking out loud. That way the object id will never change, so you shouldn't have to ever re-select it.
Tim |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Thu Jan 13, 2005 2:19 am Post subject:
Re: Too many Select Objects and get Object id |
|
|
One of the things to remember is when you pass a number to a vla-whatever.. it wants a real number, ie. 1.0 instead of 1, so if you go the way I posted you would have to change your values of nuscal to 1.0 0.5 and 10.0
Just thought that might be helpful.
Tim |
|
| Back to top |
|
 |
|
|
|
|