Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with entsel

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
DC-MWA
1490 Views, 14 Replies

Help with entsel

Hi again,

I have my sub routine working and now i want to add to my insert routine.

This line:

(setq bnm (cdr (assoc 2 (entget (car (entsel "\nSelect Detail Tag Block: ")))))

 

needs to access the last block inserted. I've tried entlast but it feeds different information.

See attached code.

 

14 REPLIES 14
Message 2 of 15
marko_ribar
in reply to: DC-MWA

I've merely inserted one line instead of your (entsel) version, and it's untested, but I suppose that it do what you asked for...

 

;creates hyperlink to drawing and view based on attribute values of detail block.
;
(defun c:test4 ( / cmde bnm blks i ent DETAILNO SHEETNO HYPERPATH )
  (setq cmde (getvar 'cmdecho))
  (setvar "cmdecho" 0)
  (setq bnm (cdr (assoc 2 (entget (car (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "INSERT"))))))))))
  ;(setq bnm (cdr (assoc 2 (entget (car (entsel "\nSelect Detail Tag Block: "))))));;;select last block inserted instead?;look in previous line ^^
  (setq blks (ssget "_X" (list (cons 2 bnm) '(66 . 1))))
  (repeat (setq i (sslength blks))
    (setq ent (ssname blks (setq i (1- i))))
    (setq DETAILNO (getpropertyvalue ent "XX"))
    (setq SHEETNO (getpropertyvalue ent "XXXX"))
    (setq HYPERPATH (strcat SHEETNO " - ARCHITECTURAL DETAILS.dwg#" DETAILNO))
    (command "detachurl" ent "")
    (command "-hyperlink" "insert" "object" ent "" HYPERPATH "" "")
  );end repeat
  (prompt "\n....\nCreating Hyperlink to detail drawing...")
  (princ (strcat "\nLink to detail #" DETAILNO " on sheet " SHEETNO " complete."))
  (setvar "cmdecho" cmde)
  (princ)
)

Regards...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 3 of 15
DannyNL
in reply to: marko_ribar

If you only want the block name of the last inserted block, you can leave the MAPCAR out I guess.

 

(setq bnm (cdr (assoc 2 (entget (cadr (car (ssnamex (ssget "_X" '((0 . "INSERT"))))))))))
Message 4 of 15
Moshe-A
in reply to: DC-MWA

@DC-MWA hi,

 

i see you are very active lately and you are learning a lot and we all very happy to see that - so keep up the good work Smiley LOL

 

above the good help you got from @marko_ribar  and @DannyNL  i have one remark:

 

where user interaction involves e.g pausing to get some input, better to bring in consideration that wrong\unexpected value will enter plus this is the spot where the user will also want to exit (or escape)

good programming code must take care of these situations - agree?!

 

so when using (entsel) or (getXXXX) functions first check the value entered and only if it's positive value you expected continue your program otherwise you end up with autolisp error (not nice).

 

for example:

 

(if (and
      (setq pick (entsel "\nSelect block: "))
      (setq elist (entget (car pick)))			; get entity database
      (eq (strcase (cdr (assoc 0 elist))) "INSERT")	; verifies it's a block
      (eq (strcase (cdr (assoc 2 elist))) "BLOCKNAME")	; verifies it's name
      (= (cdr (assoc 66 elist)) 1)			; has attributes?
    )
 (progn
  ; continue your code
  ; ...
  ; ..
  ; .
 ); progn
); if

as you can see if the user want's to exist he can just press enter (or even in this case pick on empty point)

if the entity selected is not an attribute block with the expected name the program is quiet exit Smiley LOL

 

enjoy

moshe

 

 

 

Message 5 of 15
DC-MWA
in reply to: Moshe-A

Thank you Moshe. I always learn and value your input.

Your patience and wisdom are much appreciated.

Message 6 of 15
DC-MWA
in reply to: DannyNL

I tried both the versions you sent.

I get error:

bad argument type: lselsetp nil

Message 7 of 15
DC-MWA
in reply to: marko_ribar

I tried what you sent and I get error:

bad argument type: lselsetp nil

Any ideas?

Message 8 of 15
marko_ribar
in reply to: DC-MWA

Are you sure your last inserted block is attributed block with property parameters you are expecting to obtain and use later in hyperlinking corresponding references matching its name? Your drawing either don't have blocks inserted or there are no matching attributed references so that your last insertion block is without attributes in its main definition. That is an error you received... When you fix your drawing situation, you may encounter next error also depending of current drawing situation and weather your blocks have properties you hard coded as "XX" and "XXX" from which you want to obtain values for later hyperlinking... Next your blocks may not already have assigned hyperlinks so that perhaps line with "detachurl" is surplus and maybe not needed - you should consider checking for hyperlink data assignments prior to hard coding step for detaching url...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 9 of 15
DC-MWA
in reply to: marko_ribar

See attached drawing with detail block inserted.

Message 10 of 15
marko_ribar
in reply to: DC-MWA

Like I said, that block in Model Space isn't your last inserted block in complete CAD database - there are blocks in other Layouts... So consider this quick fix, but you should also read my previous advice and debug your code further more until its all correct...

 

;creates hyperlink to drawing and view based on attribute values of detail block.
;
(defun c:test4 ( / cmde bnm blks i ent DETAILNO SHEETNO HYPERPATH )
  (setq cmde (getvar 'cmdecho))
  (setvar "cmdecho" 0)
  (setq bnm (cdr (assoc 2 (entget (car (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "INSERT") (410 . "Model"))))))))))
  ;(setq bnm (cdr (assoc 2 (entget (car (entsel "\nSelect Detail Tag Block: "))))));;;select last block inserted instead?;look in previous line ^^
  (setq blks (ssget "_X" (list (cons 2 bnm) '(66 . 1))))
  (repeat (setq i (sslength blks))
    (setq ent (ssname blks (setq i (1- i))))
    (setq DETAILNO (getpropertyvalue ent "XX"))
    (setq SHEETNO (getpropertyvalue ent "XXXX"))
    (setq HYPERPATH (strcat SHEETNO " - ARCHITECTURAL DETAILS.dwg#" DETAILNO))
    (command "detachurl" ent "")
    (command "-hyperlink" "insert" "object" ent "" HYPERPATH "" "")
  );end repeat
  (prompt "\n....\nCreating Hyperlink to detail drawing...")
  (princ (strcat "\nLink to detail #" DETAILNO " on sheet " SHEETNO " complete."))
  (setvar "cmdecho" cmde)
  (princ)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 11 of 15
DC-MWA
in reply to: marko_ribar

I'm confused. If I insert the block and know it's the operation performed. Is it not the last item in drawing? If I enter move "last" it selects the block in question?

Please advise.

 

The quick fix seems to work though. 

Message 12 of 15
marko_ribar
in reply to: DC-MWA


@DC-MWA wrote:

I'm confused. If I insert the block and know it's the operation performed. Is it not the last item in drawing? If I enter move "last" it selects the block in question?

Please advise.

 

The quick fix seems to work though. 


Yes, it's not last entity in database - Model Space is first and then follows Layouts in order they appear in Layout Tab...

That was though quick fix... I recommend better one - checking your currently active space :

 

;creates hyperlink to drawing and view based on attribute values of detail block.
;
(defun c:test4 ( / cmde bnm blks i ent DETAILNO SHEETNO HYPERPATH )
  (setq cmde (getvar 'cmdecho))
  (setvar "cmdecho" 0)
  (setq bnm (cdr (assoc 2 (entget (car (mapcar 'cadr (ssnamex (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar 'ctab)))))))))))
  ;(setq bnm (cdr (assoc 2 (entget (car (entsel "\nSelect Detail Tag Block: "))))));;;select last block inserted instead?;look in previous line ^^
  (setq blks (ssget "_X" (list (cons 2 bnm) '(66 . 1))))
  (repeat (setq i (sslength blks))
    (setq ent (ssname blks (setq i (1- i))))
    (setq DETAILNO (getpropertyvalue ent "XX"))
    (setq SHEETNO (getpropertyvalue ent "XXXX"))
    (setq HYPERPATH (strcat SHEETNO " - ARCHITECTURAL DETAILS.dwg#" DETAILNO))
    (command "detachurl" ent "")
    (command "-hyperlink" "insert" "object" ent "" HYPERPATH "" "")
  );end repeat
  (prompt "\n....\nCreating Hyperlink to detail drawing...")
  (princ (strcat "\nLink to detail #" DETAILNO " on sheet " SHEETNO " complete."))
  (setvar "cmdecho" cmde)
  (princ)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 13 of 15
ronjonp
in reply to: DC-MWA

When possible use a function ( vla-insertblock ) that will return an object rather than relying on (entlast). Then you know for sure you have the correct object.

 

It is not necessary to convert the pickset to a list since you're only interested in the first item:

(setq bn (cond ((setq s (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar 'ctab)))))
		(cdr (assoc 2 (entget (ssname s 0))))
	       )
	 )
)
Message 14 of 15
marko_ribar
in reply to: ronjonp

You are right @ronjonp ... BTW. I've checked - no errors if (command "_.detachurl" ent "") is applied and previously no urls attached... So everything should work IMHO as it is posted, though I'd avoid using (getpropertyvalue) function as prior A2012 those weren't implemented ((getpropertyvalue) (setpropertyvalue) (dumpallproperties))... Instead I'd iterate through block reference definition and find those attributes from which I'd pull out values...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 15 of 15
DC-MWA
in reply to: marko_ribar

Thanks for the valued input and assistance.

As far as command not working in previous versions....  Autodesk is gifted and making ways for us to keep using and/or purchasing the latest and greatest software. So for our firm. This should suffice.

Thanks again.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost