(entget (car (entsel))) for pline

(entget (car (entsel))) for pline

alexandre_benekowski
Advocate Advocate
5,158 Views
10 Replies
Message 1 of 11

(entget (car (entsel))) for pline

alexandre_benekowski
Advocate
Advocate

Hi people!!!!

 

I´m trying write a code that insert a block in an each point of vertex, but all vertex has the same number (10) and the block just insert in the first point.

 

see my code:

 

(defun c:test ()

(setvar "osmode" 0)
(setq selecao_geral (ssget))
(setq s1 (ssget "_p" '((0 . "LWPOLYLINE") (8 . "F-SC-GREIDE"))))
(setq pline (cdr (assoc 10 (entget (ssname s1 0)))))
(command "_insert" "C:/Users/alexa/Desktop/Alexandre/12.LISP'S PARA AUTOCAD/BLOCOS/PIRULITO" pline "1" "1" "0" "XX")
(princ)
)

 

how can i insert blocks in all vertex?

 

Please!!!!

0 Likes
Replies (10)
Message 2 of 11

Ranjit_Singh
Advisor
Advisor
Accepted solution

Maybe like this

(defun c:test  (/ ctr s1)
  (setvar "osmode" 0)
  (setq s1  (ssget  '((0 . "LWPOLYLINE") (8 . "F-SC-GREIDE")))
        ctr 0)
  (repeat (sslength s1)
    (foreach i  (cdr (reverse (vl-remove-if-not 'listp (mapcar 'cdr (entget (ssname s1 ctr))))))
      (command "_insert" "C:/Users/alexa/Desktop/Alexandre/12.LISP'S PARA AUTOCAD/BLOCOS/PIRULITO" i "1" "1" "0" "XX"))
    (setq ctr (1+ ctr)))
  (princ))

Also note that you do not need to get selectionset and then call previous. I am not sure of the "XX" argument, may be that is for some attribute.insert_blocks.gif

 

Message 3 of 11

dbroad
Mentor
Mentor
Accepted solution

@Ranjit_Singh's got a solution that is close but might not discriminate the list enough. In addition to points, there is an extrusion vector list which would cause an extra block to be inserted.  This approach would also work but without the extra insertion.  I commented out your layer and block command.  Just uncomment it.

 

(defun c:test ()
  (setvar "osmode" 0)
  (setvar "pdmode" 3) ;added to make points visible.
  ;;(setq selecao_geral (ssget))
  (setq s1 (ssget '((0 . "LWPOLYLINE") ;|(8 . "F-SC-GREIDE")|;)))
  (foreach n (cdrs 10 (entget (ssname s1 0)))
    ;;(command "_insert" "C:/Users/alexa/Desktop/Alexandre/12.LISP'S PARA AUTOCAD/BLOCOS/PIRULITO" n "1" "1" "0" "XX")
    (command "point" n)
  )
  (princ)
)


;;;This little routine will return a list of all
;;;instances of the supplied association pointer. Use like so:
;;;(cdrs 10 (entget (car (entsel "\nSelect a polyline"))))
;;;returns something like this:
;;;((259.943 -252.219) (214.182 -140.305) (254.223 -92.925) (215.0 -21.0386)
;;;(253.406 41.8621) (215.817 112.115))
;;;Michael Puckett
(defun cdrs (key lst / pair rtn)
  (while (setq pair (assoc key lst))
    (setq rtn (cons (cdr pair) rtn)
	  lst (cdr (member pair lst))
    )
  )
  (reverse rtn)
)
Architect, Registered NC, VA, SC, & GA.
Message 4 of 11

Ranjit_Singh
Advisor
Advisor
Accepted solution

@Anonymous wrote:

@Ranjit_Singh's got a solution that is close but might not discriminate the list enough. In addition to points, there is an extrusion vector list which would cause an extra block to be inserted.  This approach would also work but without the extra insertion.  I commented out your layer and block command.  Just uncomment it. 


 

@dbroad I thought I removed the extrusion vector with the (cdr (reverse... am I missing something?

EDIT: I guess not.

Message 5 of 11

dbroad
Mentor
Mentor
Accepted solution

Sorry I missed that.  Thanks for pointing that out. The method, however, does make assumptions about the order of the entget list (that the extrusion vector will always be last).  Though It is not likely that the order will change, by selecting only the 10 association groups you are guaranteed not to get any other items.

Architect, Registered NC, VA, SC, & GA.
Message 6 of 11

Ranjit_Singh
Advisor
Advisor
Accepted solution

@Anonymous wrote:

Sorry I missed that.  Thanks for pointing that out. The method, however, does make assumptions about the order of the entget list (that the extrusion vector will always be last).  Though It is not likely that the order will change, by selecting only the 10 association groups you are guaranteed not to get any other items.


Yes, I see your point. Kudos!

But wait, what if DXF 10 changes to 11. Then is my code better? Maybe not even then, since dxf 10 going to 11 is extremely less likely when compared to the dxf order changing. No assumptions there, since I exactly know how Autodesk will design every upcoming release Smiley Wink

Message 7 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

Another approach to the same operation, with some variations for certain particular situations, is on this thread.

Kent Cooper, AIA
Message 8 of 11

dbroad
Mentor
Mentor
Accepted solution

Thanks for the link @Kent1Cooper.

 

@Ranjit_Singh:  A small substitution in your program should preserve the association list methodology, but as you say, yours works fine as is, for now. Smiley Tongue

 

....
(foreach i (mapcar 'cdr (vl-remove-if-not (function lambda (n)(= 10 (car n))) (entget (ssname s1 ctr))))
  ...)

 

 

 

 

Architect, Registered NC, VA, SC, & GA.
Message 9 of 11

Ranjit_Singh
Advisor
Advisor
Accepted solution

@Anonymous wrote:

Thanks for the link @Kent1Cooper.

 

@Ranjit_Singh:  A small substitution in your program should preserve the association list methodology, but as you say, yours works fine as is, for now. Smiley Tongue


You didn't quite address what happens when 10 goes to 11. Or what if they really pull a number and use 10 and 11 codes like in lines Smiley LOL

0 Likes
Message 10 of 11

john.uhden
Mentor
Mentor
Accepted solution

Ya know, I thought I was one of the oldest farts around here, but @Ranjit_Singh and @dbroad are making me look like a youngster,

 

To get the vertices of a lightweight polyline object...

 

(setq pts (@group (vlax-get lwpolyobj 'Coordinates) 2))
;; where...
(defun @group (old n / item new)
  (while old
    (while (< (length item) n)
      (setq item (cons (car old) item) old (cdr old))
    )
    (setq new (cons (reverse item) new) item nil)
  )
  (reverse new)
)

John F. Uhden

Message 11 of 11

alexandre_benekowski
Advocate
Advocate
Accepted solution

Thank you people!!!!!!!

 

it worked!!!!

 

Thank you very much!!!!

 

Smiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley HappySmiley Happy

0 Likes