Ycoord of last entity in a selection set

Ycoord of last entity in a selection set

LFM.VDC
Enthusiast Enthusiast
1,280 Views
13 Replies
Message 1 of 14

Ycoord of last entity in a selection set

LFM.VDC
Enthusiast
Enthusiast

Hi everybody, 

 

    I need a little help... I need to be able to access the coordinates of the last entity in a selection set. Can anyone help?

Luciano
0 Likes
1,281 Views
13 Replies
Replies (13)
Message 2 of 14

Ranjit_Singh
Advisor
Advisor

Can you provide some more information. What is the last entity? Just determine the last entity type and get the relevant dxf codes. But many questions arise. If it's a polyline, for instance, do you just want the last vertex or all vertices? Post the relevant code in question and more relevant help can be provided.

0 Likes
Message 3 of 14

LFM.VDC
Enthusiast
Enthusiast

Thanks for responding, so here is the code and I am only learnig lisp now as mony of us on the Forum. What i would like to do with this code is make it a bit more dynamic. 

 

 I need to get the code Highlighted in red to run on as many entities  as are selected, without being limited to how this code is written. Which right now limits me to three entities, the entities are third party pipe objects. Fabrication CADMEP. 

 

(defun c:racktext1()
(setq sset(ssget))
(setq elsset(ssget))

 

(setq pnt(getpoint "\n Text Position"))
(setq Xcoord(car pnt))
(setq Ycoord(cadr pnt))
(setq Zcoord(Caddr pnt))

 

(setq SPACING 5.5)


(addTextatpoint 2 (ssname sset 0) pnt)
(setq pnt(list Xcoord(- Ycoord Spacing)Zcoord))
(addTextAtpoint 2 (ssname sset 1) pnt)
(setq pnt(list Xcoord(- Ycoord (* Spacing 2)) Zcoord))
(addTextAtpoint 2 (ssname sset 2) pnt)



(setq pnt(list Xcoord(- Ycoord Spacing)Zcoord)) 
(addTextAtpoint 3 (ssname elsset 0 ) pnt)
(princ)
)

Luciano
0 Likes
Message 4 of 14

Kent1Cooper
Consultant
Consultant

@LFM.VDC wrote:

.... 

 I need to get the code Highlighted in red to run on as many entities  as are selected, without being limited to how this code is written. Which right now limits me to three entities.... 

....

(addTextatpoint 2 (ssname sset 0) pnt)
(setq pnt(list Xcoord(- Ycoord Spacing)Zcoord))
(addTextAtpoint 2 (ssname sset 1) pnt)
(setq pnt(list Xcoord(- Ycoord (* Spacing 2)) Zcoord))
....


There are some things I don't quite understand, but it looks like you're trying to move down by an additional Spacing distance in the Y direction with each object.  One way to do that would be to use an integer variable that can serve for both the index value of the item in the selection set and the multiplier for the Y-coordinate down-stepping, incrementing that position-and-multiplier variable as you go, something like:

 

(setq n 0); starting value

(repeat (sslength sset)

  (addTextatpoint 2 (ssname sset n)

    (list Xcoord (- Ycoord (* Spacing (setq n (1+ n)))) Zcoord)

  ); addT...

); repeat

 

The first time, it will find the index-0 item [the first one] in the selection set, and set the Y coordinate position down by [setting n one higher at that point] one Spacing, and the second time, with n having been raised by one, it will find the index-1 item [the second one] in the selection set, and set the Y coordinate position down by two Spacings, and so on.

Kent Cooper, AIA
0 Likes
Message 5 of 14

LFM.VDC
Enthusiast
Enthusiast

Kent, 

 

        Is it possible to write this program in a way that it looks at the first selection set and repeats the add text at point for the same amounts of entities as are in the selection set  "sset" ?

 

 

Luciano
0 Likes
Message 6 of 14

LFM.VDC
Enthusiast
Enthusiast

I was thinking of something along the lines of this:

I don't want the code to limit the amount of times I can use the "addTextAtPoint"

 

(defun c:test2 ( / e i s x )
(setq sset(ssget))
(setq elsset(ssget))

(setq pnt(getpoint "\n Text Position"))
(setq Xcoord(car pnt))
(setq Ycoord(cadr pnt))
(setq Zcoord(Caddr pnt))

(if (setq sset (ssget))
(progn
(setq i 0)
(repeat (sslength s)
(setq e (ssname s i)
x (cdr (assoc 0 (entget e)))
i (1- i)
(addTextatpoint 2 (ssname sset i) pnt)
(setq pnt(list Xcoord (- Ycoord (* Spacing (setq n (1+ n)))) Zcoord)
)
(print x)
)
)
)
(princ)
)

Luciano
0 Likes
Message 7 of 14

Kent1Cooper
Consultant
Consultant
(defun c:test2 (/ sset elsset pnt Xcoord Ycoord Zcoord e i x )
;;; [don't need space before /; added more and replaced s with sset] (setq ;;; combining into one (setq) function: sset (ssget) elsset (ssget) pnt (getpoint "\n Text Position") Xcoord (car pnt) Ycoord (cadr pnt) Zcoord (caddr pnt) ); setq ;;;(if (setq sset (ssget)) ;;; that will ask them to select again; just do: (if sset (progn (setq i 0) ;;; (repeat (sslength s);;; don't have an 's' variable -- I assume: (repeat (sslength sset) (setq ;;; e (ssname s i);;; likewise, I assume: e (ssname sset i) x (cdr (assoc 0 (entget e))) i (1- i) ); setq [missing from yours] (addTextatpoint 2 (ssname sset i) pnt);;; already have entity; just do: (addTextatpoint 2 e pnt) ;;; (setq pnt (list Xcoord (- Ycoord (* Spacing (setq n (1+ n)))) Zcoord));;; not 'n': (setq pnt (list Xcoord (- Ycoord (* Spacing (setq i (1+ i)))) Zcoord)) (print x) ); repeat ); progn ); if (princ) ); defun

... again, assuming I am understanding correctly what you want to do....  No use seems to be made of the 'elsset' selection.  [Should that maybe be the one in place of the 's' variables, rather than 'sset' as I assumed?]

 

Kent Cooper, AIA
0 Likes
Message 8 of 14

Ranjit_Singh
Advisor
Advisor

I am still not sure on what the end goal is. Can you explain in more simplistic terms? Forget about selection sets and all technical lisp code. Just explain what you are trying to do. Maybe post a sample drawing with a small subset of entities and explain in terms of those entities like, for instance, "I want to

1. select all MTEXT entities

2. move all the entities by certain amount (or whatever your requirement is)

3. ... and

4...."

Right now, we are all guessing as to what you are trying to accomplish.

0 Likes
Message 9 of 14

LFM.VDC
Enthusiast
Enthusiast

The (addtextAtpoint) is new, this code is meant to work with the Fabrication CADMEP  add-in, in that 3rd Party Software which Autodesk acquired a few years ago they sometimes come out with new tools such as (AddTextAtpoint) as a productivity tools. Fabrication CADMEP is a piping software, the (AddTextAtPoint) is meant to allow the user to list various properties of a pipe  with one command, and have these text properties such as"Size" and "Elevation" to be aligned. 

    The code I had access to was static, if I coded for it to pick properties for a rack of three pipes and I had a job with 4 pipe rack I would  have to make a lisp routine for each size pipe rack, which isn't efficient and may cause confusion among the users. It brings me to my current issue which may have been solved by Kent in the code he posted above. I don't know if I have explained my self well enough but, I would gladly answer any questions you may have.

   So in summary what I wold like to accomplish is to select a rack of pipe and have all the sizes and systems show up aligned at a point picked by the user and make a second selection for 1 pipe on that rack for elelvation.

 

Luciano
0 Likes
Message 10 of 14

LFM.VDC
Enthusiast
Enthusiast
0 Likes
Message 11 of 14

LFM.VDC
Enthusiast
Enthusiast
0 Likes
Message 12 of 14

LFM.VDC
Enthusiast
Enthusiast

The attached Screen cast should further help in the explanation of what I am trying to accomplish.

Luciano
0 Likes
Message 13 of 14

Ranjit_Singh
Advisor
Advisor

Luciano, I do not see any screencast, but the Autodesk link helped. I believe Kent1Cooper has already answered the question. Just setq spacing and see if it works.

0 Likes
Message 14 of 14

LFM.VDC
Enthusiast
Enthusiast

 

Luciano
0 Likes