fathihvac Posted August 12, 2011 Share Posted August 12, 2011 Hello Everybody, I am looking for a code that extract the name of a block. Quote Link to comment Share on other sites More sharing options...
pBe Posted August 12, 2011 Share Posted August 12, 2011 (edited) (defun c:GetBlkName (/ ent) [b][color=blue](vl-load-com)[/color][/b] (cond ((and (setq ent (car (entsel "\nSelect Block Entity: "))) (eq (cdr (assoc 0 (entget ent))) "INSERT") (alert (strcat "Block Name:" (vla-get-effectivename (vlax-ename->vla-object ent))))) ))) (cdr (assoc 2 (entget ent)));;<---[i]ent[/i] as ename (vla-get-effectivename (vlax-ename->vla-object ent));<---[i]ent [/i]as vla object Edited August 12, 2011 by pBe add (vl-load-com) Quote Link to comment Share on other sites More sharing options...
fathihvac Posted August 12, 2011 Author Share Posted August 12, 2011 thanks The following error occured Select Block Entity: ; error: no function definition: VLAX-ENAME->VLA-OBJECT Quote Link to comment Share on other sites More sharing options...
fathihvac Posted August 12, 2011 Author Share Posted August 12, 2011 still not working Please could you use the lisp to see what's wrong? Quote Link to comment Share on other sites More sharing options...
dbroada Posted August 12, 2011 Share Posted August 12, 2011 it works for me Quote Link to comment Share on other sites More sharing options...
fathihvac Posted August 12, 2011 Author Share Posted August 12, 2011 Could you write again the whole code you are using? Quote Link to comment Share on other sites More sharing options...
dbroada Posted August 12, 2011 Share Posted August 12, 2011 THIS (defun c:GetBlkName (/ ent) (cond ((and (setq ent (car (entsel "\nSelect Block Entity: "))) (eq (cdr (assoc 0 (entget ent))) "INSERT") (alert (strcat "Block Name:" (vla-get-effectivename (vlax-ename->vla-object ent))))) ))) works for me. Quote Link to comment Share on other sites More sharing options...
pBe Posted August 12, 2011 Share Posted August 12, 2011 Add this after (defun c:GetBlkName (/ ent) (vl-load-com) ..... My bad Quote Link to comment Share on other sites More sharing options...
fathihvac Posted August 12, 2011 Author Share Posted August 12, 2011 I still got the error Select Block Entity: ; error: no function definition: VLAX-ENAME->VLA-OBJECT Quote Link to comment Share on other sites More sharing options...
fathihvac Posted August 12, 2011 Author Share Posted August 12, 2011 That's ok Thanks Could you make it so it insert the block name as text string to the drawing area? Quote Link to comment Share on other sites More sharing options...
pBe Posted August 12, 2011 Share Posted August 12, 2011 I still got the errorSelect Block Entity: ; error: no function definition: VLAX-ENAME->VLA-OBJECT Are you sure? See first Edited post Quote Link to comment Share on other sites More sharing options...
fathihvac Posted August 12, 2011 Author Share Posted August 12, 2011 Are you sure? See first Edited post The code is missing (vl-load-com) Now that's ok Many Thanks. Can modify it to insert the block name as text string in the drawing area? Quote Link to comment Share on other sites More sharing options...
pBe Posted August 12, 2011 Share Posted August 12, 2011 Can modify it to insert the block name as text string in the drawing area? What do you mean? A Text Entity to be placed on screen? Quote Link to comment Share on other sites More sharing options...
fathihvac Posted August 12, 2011 Author Share Posted August 12, 2011 Yes That what i mean Quote Link to comment Share on other sites More sharing options...
pBe Posted August 12, 2011 Share Posted August 12, 2011 (edited) (defun c:GetBlkName (/ ent) (vl-load-com) [color=blue](defun _MText ( point text)[/color] [color=blue] (entmakex[/color] [color=blue] (list[/color] [color=blue] (cons 0 "MTEXT")[/color] [color=blue] (cons 100 "AcDbEntity")[/color] [color=blue] (cons 100 "AcDbMText")[/color] [color=blue] (cons 7 (getvar 'Textstyle))[/color] [color=blue] (cons 10 point)[/color] [color=blue] (cons 11 (getvar 'UCSXDIR))[/color] [color=blue] (cons 1 text)[/color] [color=blue] )[/color] [color=blue] )[/color] ) (cond ((and (setq ent (car (entsel "\nSelect Block Entity: "))) (eq (cdr (assoc 0 (entget ent))) "INSERT") [color=red](setq STR (vla-get-effectivename (vlax-ename->vla-object ent))) [/color] [color=blue] (Setq pt (getpoint "\nPick Point to place Text: "))[/color] [color=blue] (_Mtext pt str )[/color] ))) ) The Text created by this routine will depend on your current Text Style. Other factors to consider are: -Text Justification -Layer -Rotation -Annotative or not Hope this helps Edited August 12, 2011 by pBe Remove Alert Quote Link to comment Share on other sites More sharing options...
fathihvac Posted August 12, 2011 Author Share Posted August 12, 2011 Many Thanks:) But could you remove the alert Quote Link to comment Share on other sites More sharing options...
troggarf Posted August 12, 2011 Share Posted August 12, 2011 Here's a routine I found that lets you select a block and then place the name of the block as text. Click HERE to see it in action ;; BN.LSP Control Systems & Services, Inc. ;; Visit me at: http://www.bobscadshop.com (DEFUN C:BN () ; comment out next 2 lines if you don't want a point at the insertion point (setq bn "" chk nil); set block name nil (while (= chk nil) (setq chk (entsel "\nPick a Block: ")) ); end while (setq pp (cadr chk)) (setq chk (entget (car chk))) (setq bn (cdr (assoc 2 chk))); get block name (setq ip (cdr (assoc 10 chk))); get insertion point (setq A (car (getvar "LIMMAX"))) (if (> A 40) (setq TSIZ "0.5") (setq TSIZ "0.1875") ); end if (setq ipt (getpoint "\nPlace Block Name Where : ")) (if (/= bn "") (command "_text" "_c" ipt TSIZ "0" bn); apply block name ); end if (if (= bn "") (prompt "\nCannot find the Blockname ?? : ") ); end if ; comment out next line if you don't want a point at the insertion point (setq ip nil bn nil chk nil pp nil A nil ipt nil); cleanup (princ) ); end function Quote Link to comment Share on other sites More sharing options...
troggarf Posted August 12, 2011 Share Posted August 12, 2011 Oops, Posted the wrong one. Here is the one that is featured on my blog. ; places name of block as text via pick (defun C:blockn() (setvar "cmdecho" 0) (setq pt(cadr(entsel"\nSelect Block:"))) (setq e1(ssget pt)) (setq e2 (entget (ssname e1 0))) (setq blname (cdr(assoc 2 e2))) (setq pt1 (getpoint"\nSelect point for block title:")) (command "text" pt1 "" 0 blname) ) Quote Link to comment Share on other sites More sharing options...
LISP2LEARN Posted August 13, 2011 Share Posted August 13, 2011 That's ok ThanksCould you make it so it insert the block name as text string to the drawing area? Try this, but it gives an error if selected entity is not a block. I don't know where to put the "while & not" functions. (defun c:test (/ ent point) (cond ((and (setq ent (car (entsel "\nSelect Block Entity: "))) (eq (cdr (assoc 0 (entget ent))) "INSERT") (setq point (getpoint "\nSelect insertion point :")) )) ) (entmakex (list (cons 0 "TEXT") (cons 7 (getvar 'TEXTSTYLE)) (cons 40 (cons 8 "0") ;LAYER (cons 10 point) (cons 1 (cdr (assoc 2 (entget ent)))) (cons 41 1) (cons 50 0) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
pBe Posted August 13, 2011 Share Posted August 13, 2011 (edited) Try this, but it gives an error if selected entity is not a block. I don't know where to put the "while & not" functions. ...(cons 1 (cdr (assoc 2 (entget ent)))).... ;<--- if the selected entity is not a block this will error as variable [i]ent [/i]doesnt have the DXF group code 2 You can wrap entmakex inside the (cond ((and ...))). that way if (eq (cdr (assoc 0 (entget ent))) "INSERT") is nil there is no reason for the program to continue then it will stop evaluating the next condition. now using IF outside the cond wrap, you can use this (if point (entmakex.....)) , only if variable point is not nil that this expression willl evaluate, since the previous condition only allows the evaluation of point variable after the first two conditions are met. Hope this helps Edited August 13, 2011 by pBe Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.