MarcoW Posted June 6, 2009 Share Posted June 6, 2009 Hello, To determine information of a block in a drawing, for example the block's name, I use this code: (cdr (assoc 2 (entget (car (entsel))))) It nicely returns the blocks name. This does not seem to work when I want to get the blocks name when the block is in an xref. Can it be done, and if so, how? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 6, 2009 Share Posted June 6, 2009 I'm not sure why that is failing you It should work Quote Link to comment Share on other sites More sharing options...
MarcoW Posted June 6, 2009 Author Share Posted June 6, 2009 It then selects the insertion point of the whole xref. Quote Link to comment Share on other sites More sharing options...
MarcoW Posted June 6, 2009 Author Share Posted June 6, 2009 From a various blocks in an xref i need to get the insertion point and the rotation angle. So I can calculate a point that lies 15mm to the opposiste direction. Ie. when a block with insertion point 0,0 (lets call that point pt1) at rotation 0 is selected i need to "setq pt2" at (polar insertionpointblock pi 15). So in the opposite direction with an offset 15mm. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 6, 2009 Share Posted June 6, 2009 Insertion point is DXF 10, and rotation is DXF 50 code. Alternatively, these values can be obtained through Visual LISP methods. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 6, 2009 Share Posted June 6, 2009 Hence, to get your point ~ ([b][color=Blue]polar[/color][/b] ([b][color=Blue]cdr[/color][/b] ([b][color=Blue]assoc[/color][/b] [color=Green][b]10[/b][/color] ([b][color=Blue]entget[/color][/b] [b][color=Red]<ename>[/color][/b]))) [color=Purple][b][i]; Insertion Point[/i][/b][/color] ([b][color=Blue]+[/color][/b] [color=Blue][b]pi[/b][/color] ([b][color=Blue]cdr[/color][/b] ([b][color=Blue]assoc[/color][/b] [b][color=Green]50[/color][/b] ([color=Blue][b]entget[/b][/color] [color=Red][b]<ename>[/b][/color]))) [color=Purple][b][i]; Rotation[/i][/b][/color] ) [i][color=Purple][b]; End Addition[/b][/color][/i] [color=Green][b]15[/b][/color] ) [color=Purple][i][b]; end polar[/b][/i][/color] Hope this helps Lee Quote Link to comment Share on other sites More sharing options...
MarcoW Posted June 7, 2009 Author Share Posted June 7, 2009 Hi Lee, I originally had this code (found somewhere on the internet): (defun C:test () (setq TOTAL 0.) (setvar "OSMODE" 0) (print "Please Select blocks") (setq SSPICK (ssget)) (setq SSAMT (sslength SSPICK)) (setq INDEX 0.) ; (while (< INDEX SSAMT); Selection Set Loop (setq ENT-NO (ssname SSPICK INDEX)) (setq DXF (entget ENT-NO)) (setq XYZ (cdr (assoc 10 DXF))) (command "insert" "TESTBLOCK" XYZ 1 "" "") ; TESTBLOCK = Yes... (princ) (setq INDEX (+ INDEX 1.)) (princ INDEX) (print ENT-NO) ); end while (princ) ) First of al some questions you might wanna explain for I do not know where I got the code from, so I can't ask there. 1. I see: TOTAL = variable: set to 0 at the beginning. --> What is the dot (.) doing there? 2. Osmode is turned off 3. Promting for action and then (setq SSPICK (ssget)). 4. SSPICK = the selected blocks /things are put in the SSPICK variable 5. (setq SSAMT (sslength SSPICK)) = thats "counting" the blocks / items that are placed in SSPICK correct? 6. Aigan a variable set to zero, and again a dot ... why? 7. While function -> as long as index is less than ssamt it loops between (while .... and ); end while, correct? 8. These 3 lines is do not get: (setq ENT-NO (ssname SSPICK INDEX)) It sets variable ENT-NO to (....?) (setq DXF (entget ENT-NO)) It sets varible DXF to (entget ENT-NO) (setq XYZ (cdr (assoc 10 DXF))) XYZ is the point gotten out of (cdr (assoc 10 dxf))) wich is the insertion point. 9. (setq INDEX (+ INDEX 1.)) here 1 is added to INDEX ... 10. THen index and ENT-NO are printed out on the commandline 11. If index is less than ssamt it loops back else end of function. I wouldn't be able to create above lisp from scratch but learning to read the code is part of learning process I gUess. The code above works for what I need to do: place a block on anothers block insertion point. It does not work on block in an xref, that I have to modify (try to). YOur code might help: (polar (cdr (assoc 10 (entget <ename>))) ; Insertion Point (+ pi (cdr (assoc 50 (entget <ename>))) ; Rotation ) ; End Addition 15 ) ; end polar But how to put both together? Can you help me get started? (defun C:test () (setvar "OSMODE" 0) (setq TOTAL 0.) (print "Please Select blocks") (setq SSPICK (ssget)) SSAMT (sslength SSPICK) INDEX 0.) ) (while (< INDEX SSAMT); Selection Set Loop (setq ENT-NO (ssname SSPICK INDEX) DXF (entget ENT-NO) XYZ (cdr (assoc 10 DXF)) ) (command "insert" "TESTBLOCK" XYZ 1 "" "") ; TESTBLOCK = Yes... (princ) (setq INDEX (+ INDEX 1.)) (princ INDEX) (print ENT-NO) ); end while (princ) ) Thnanks in advance. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 7, 2009 Share Posted June 7, 2009 1. I see: TOTAL = variable: set to 0 at the beginning. --> What is the dot (.) doing there? The Dot is to make it a REAL number instead of INTEGER as the integers have a 32767 limit. 2. Osmode is turned off This is because the code uses "command" to insert the block 3. Promting for action and then (setq SSPICK (ssget)). SSGET will only display "Select Objects" for the prompt, so the user has printed another prompt. 4. SSPICK = the selected blocks /things are put in the SSPICK variable Correct 5. (setq SSAMT (sslength SSPICK)) = thats "counting" the blocks / items that are placed in SSPICK correct? Correct 6. Aigan a variable set to zero, and again a dot ... why? As above. 7. While function -> as long as index is less than ssamt it loops between (while .... and ); end while, correct? Correct 8. These 3 lines is do not get: (setq ENT-NO (ssname SSPICK INDEX)) It sets variable ENT-NO to (....?) Collects the entity name of the object in the selection set at the index denoted by INDEX. This is detailed in the Visual LISP help under "ssname". (setq DXF (entget ENT-NO)) It sets varible DXF to (entget ENT-NO) Entget's the entity name retrieved above. (setq XYZ (cdr (assoc 10 DXF))) XYZ is the point gotten out of (cdr (assoc 10 dxf))) wich is the insertion point. Get the Insertion Point from the entget list. 9. (setq INDEX (+ INDEX 1.)) here 1 is added to INDEX ... Correct 10. THen index and ENT-NO are printed out on the commandline Correct 11. If index is less than ssamt it loops back else end of function. Correct, if the index is still less than the number of elements it will carry on looping through to look at every element in the set. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 7, 2009 Share Posted June 7, 2009 Hopefull this will help you: {untested} (defun c:test (/ *error* vl ov ss i bLst pt rot pt2) ;; Always Localise the Variables! ;; Error Handler in case the user hits Esc (defun *error* (msg) (if ov (mapcar 'setvar vl ov)) ; reset Sys vars (princ (strcat "\n<< Error: " msg " >>")) ; Print Error Message (princ) ; Exit Cleanly ) ; End Error Handler (setq vl '("CMDECHO" "OSMODE") ; Sys Var list ov (mapcar 'getvar vl)) ; Get Old values (mapcar 'setvar vl '(0 0)) ; Turn off CMDECHO & OSMODE (print "Please Select blocks...") ; Prompt (if ; If a SelectionSet is picked (setq ss (ssget '((0 . "INSERT")))) ;; Filter for Blocks (progn (setq i (sslength ss)) ; get number of items in SelectionSet (while (not (minusp (setq i (1- i)))) ; While i is not Negative (setq bLst (entget (ssname ss i))) ; get Block Entity (setq pt (cdr (assoc 10 bLst)) ; Insertion Point rot (cdr (assoc 50 bLst))) ; Rotation (setq pt2 (polar pt (+ rot pi) 15)) ; Define New point (command "-insert" "testblock" pt2 "1." "1." "0.") ; Insert Block at new point ) ; End While ) ; End Progn (princ "\n<!> No Blocks Selected <!>") ; Else no Blocks were Picked ) ; end If (mapcar 'setvar vl ov) ; reset Sys Vars (princ) ; Exit Cleanly ) ; end function Quote Link to comment Share on other sites More sharing options...
MarcoW Posted June 24, 2009 Author Share Posted June 24, 2009 Lee, Still I am wondering if this routine can work when the selctable blocks are in an xref. You know what I mean? When the blocks are in the actual drawing it works very nice, when they are in the xref, the insertion point of the xref is used... My knowledge of lisp is still poor... Many thanks in advance! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 24, 2009 Share Posted June 24, 2009 Lee, Still I am wondering if this routine can work when the selctable blocks are in an xref. You know what I mean? When the blocks are in the actual drawing it works very nice, when they are in the xref, the insertion point of the xref is used... My knowledge of lisp is still poor... Many thanks in advance! Ah, I understand your situation better now - you are talking about blocks that are nested within Xrefs... a different story entirely, as, with a selection set, the program will not "see" the blocks within the xref, but just the xref itself. Quote Link to comment Share on other sites More sharing options...
dbroada Posted June 24, 2009 Share Posted June 24, 2009 it must be possible as the Express Tool XLIST does it, but I don't know how. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 24, 2009 Share Posted June 24, 2009 This is all I could think of : {untested} [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:test [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] blks ss blk xLst[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blks [b][color=RED]([/color][/b][b][color=BLUE]vla-get-Blocks[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#ff00ff]"INSERT"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blk [b][color=RED]([/color][/b][b][color=BLUE]getstring[/color][/b] [b][color=BLUE]t[/color][/b] [b][color=#ff00ff]"\nSpecify Block to Insert: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"BLOCK"[/color][/b] blk[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]findfile[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] blk [b][color=#ff00ff]".dwg"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] xLst [b][color=RED]([/color][/b][b][color=BLUE]vl-remove-if-not[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]vla-get-isXref[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]function[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b]x[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-item[/color][/b] blks [b][color=RED]([/color][/b][b][color=BLUE]vla-get-Name[/color][/b] x[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]vlax-ename->vla-object[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-remove-if[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]listp[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]cadr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]ssnamex[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] xLst [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] x xLst [b][color=RED]([/color][/b][b][color=BLUE]vlax-for[/color][/b] Obj x [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#ff00ff]"AcDbBlockReference"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ObjectName[/color][/b] Obj[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-insertblock[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ModelSpace[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-3D-point[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-safearray->list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-variant-value[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-InsertionPoint[/color][/b] Obj[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=BLUE]pi[/color][/b] [b][color=#009900]15[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] blk [b][color=RED]([/color][/b][b][color=BLUE]vla-get-XScaleFactor[/color][/b] Obj[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-YscaleFactor[/color][/b] Obj[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ZscaleFactor[/color][/b] Obj[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-Rotation[/color][/b] Obj[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<< Block Not Found >>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] Quote Link to comment Share on other sites More sharing options...
MarcoW Posted June 24, 2009 Author Share Posted June 24, 2009 Hey Lee, Thanks for the reply, but it doesn't work, I tested it... I have no clue how to modify, my Lisp is as poor as your dutch Anaway, if somone does have an idea, please share it with me / us. Tnx. 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.