Olhado_ Posted January 7, 2009 Posted January 7, 2009 We have different size borders, which I am attaching one as a sample. Anyways, I know how to find the border block by name and then locate the origin. However, I would like to be able to find the diagonal point as well, so I can create a window around it and do some other things with that point. Is there a way I can do this? The way I am thinking of is to use the dark blue box on DefPoints Layer; but I cannot find those sub-entities of a block. I don't care what language I have to use; but I would prefer LISP over VBA. Thanks again for your help. Sample_Border.dwg Quote
Lee Mac Posted January 7, 2009 Posted January 7, 2009 Hi, would be happy to help but could you upload in 2000 format please? Thanks Quote
Olhado_ Posted January 7, 2009 Author Posted January 7, 2009 Thanks! Here is the file saved as a 2000 format Sample_Border_2000.dwg Quote
Lee Mac Posted January 7, 2009 Posted January 7, 2009 If the border is the only thing in the drawing - this may help: (defun c:dwgdim (/ bt tp) (setq bt (getvar "extmin") tp (getvar "extmax") ) ;_ end setq (alert (strcat "Drawing Dimensions are: \n" (rtos (- (car tp) (car bt)) 2 2) " x " (rtos (- (cadr tp) (cadr bt)) 2 2) ) ;_ end strcat ) ;_ end alert (princ) ) ;_ end defun But its far from ideal EDIT: I didn't mean "only" thing in the drawing, I meant the "largest" thing in the drawing. Quote
Olhado_ Posted January 8, 2009 Author Posted January 8, 2009 Thanks for the help Lee that is a good start; but I cannot assume people are not going to put anything outside the border. I even do it regularly myself too. It did get the gears rolling thorough. I think I figured out a way to do it; but I cannot get the perimeter function working. Does anyone see what I am missing? The vla-Get-Area works like a charm and LISP does recognize vla-get-perimeter as a function (in editor) [color=black](vl-load-com)[/color] [color=black](command ".-boundary" "A" "I" "N" "+X" "" ".1,.1" "") ; Create Boundary around BlueBox[/color] [color=black](setq entBound (entlast)) ; Identify Boundary that was just created[/color] [color=black](setq AreaBor (vla-get-Area (vlax-ename->vla-object entBound))) ; Boundary Area[/color] [color=black](setq ParaBor (vla-get-perimeter (vlax-ename->vla-object entBound))) ; Boundary Parameter[/color] If you would believe it I originally was able to get the parameter through this test code; but now even that does not want to work. [color=black](VLA-GET-PERIMETER (vlax-ename->vla-object (car (entsel))))[/color] I get this error: ; error: ActiveX Server returned the error: unknown name: Perimeter Thanks again for the help. -Chris Quote
Olhado_ Posted January 8, 2009 Author Posted January 8, 2009 For what it is worth, here is another working code, which will work no matter what is on the outside. I am not sure if anyone else can get any use out of it, thorough. Thanks again for the help. I really appreciate it, even if I did not end up using the exact code. (command ".-boundary" "A" "I" "N" "+X" "" ".1,.1" "") ; Create Boundary around BlueBox (setq entBound (entlast)) ; Identify Boundary that was just created (setq diag (cdr (assoc 10 (entget entBound)))) Quote
Lee Mac Posted January 8, 2009 Posted January 8, 2009 Thanks Olhado, thats a generous last post. Quote
Olhado_ Posted February 6, 2009 Author Posted February 6, 2009 I guess we all thought (myself included) that this thread was closed. And I can live with the above; but I have some new information and am interested if it shows any more promise. The code below first tries to find the attached border and then tries to find the Polyline nested in the block that is currently on "Defpoints." Do you see any way of modifying this code to pick up the dark blue box? My belief is it has to be in the DWG file and if it is in there, then the program should at least be able to find the entity. (defun C:BlueBox () ;;; ============================================================== ;;; Find an AutoCAD border ;;; ========================================================== (if (setq s (ssget "x" '((-4 . "<OR") (2 . "TITLEBLOCK") (-4 . "OR>")))) (progn (alert "I found the Border") )) ; end of if ;;; ============================================================== ;;; Find the blue box in the Titleblock ;;; ============================================================== (if (setq s (ssget "x" '((-4 . "<AND") (0 . "LWPOLYLINE") (8 . "DefPoints") (-4 . "AND>")))) (progn (Alert "I found the Blue Box") )) ; end of if ) If I could get this to work, then I will not be using "Defpoints." Sample_Border.zip Quote
CarlB Posted February 7, 2009 Posted February 7, 2009 To find a part of a block (other than an attribute) you need to examine the block definition, in the "block" table. Step through that with 'entnext', find a polyline on "defpoints" (hopefully only one), extract coordinates, then adjust the coordinates relative to the block insert coordinates & rotation. Phew! Here's some code typed on the command line to find the block definition, first sub-entity: Command: (setq e1 (tblobjname "block" "titleblock")) Command: (entget e1) ((-1 . ) (0 . "BLOCK") (330 . ) (5 . "C1CF") (100 . "AcDbEntity") (67 . 0) (8 . "0") (370 . -3) (100 . "AcDbBlockBegin") (70 . 2) (10 0.0 0.0 0.0) (-2 . ) (2 . "TITLEBLOCK") (1 . "") (4 . "This is a sample Block")) Command: (entget (entnext e1)) ((-1 . ) (0 . "LINE") (330 . ) (5 . "C1D1") (100 . "AcDbEntity") (67 . 0) (8 . "BorderLine2") (6 . "Continuous") (100 . "AcDbLine") (10 39.875 3.5 0.0) (11 39.5 3.5 0.0) (210 0.0 0.0 1.0)) Quote
Lee Mac Posted February 7, 2009 Posted February 7, 2009 Nice one Carl - didn't think of that one Quote
Olhado_ Posted February 10, 2009 Author Posted February 10, 2009 Thanks CarlB that is proving helpful, although do you know any way you can get either a count of entities or break out of a loop? If you cannot do any of those, then do you think someone can help me with the general syntax of the following statements: Working Code: ([color=navy][b]if[/b][/color] (setq ssTitle (ssget [color=red]"x"[/color] [color=navy]'((-4 . "<OR") (2 . "Titleblock") (-4 . "OR>"))))[/color] (progn (setq blkent (cdr (assoc -1 (entget (ssname ssTitle 0))))) )) Syntax Trouble: (ssget [color=red]":U"[/color] blkent) ; error: too few arguments (ssget [color=red]":V"[/color] blkent) ; error: too few arguments (ssget [color=red]":U"[/color] blkent [color=navy]'(8 . "Defpoints")) ; error: too few arguments[/color] According to the Help menu those one of those selection methods appear to by my best hope; but I cannot understand how to use them. I almost would like to find out, just to find out, even if it turns out I cannot use them. Thanks. Quote
Olhado_ Posted February 10, 2009 Author Posted February 10, 2009 I wish I could take the credit; but using what you said I ended up finding this way from the forum at autodesk. (defun GetBlockEnts (Block / Blk Next EntLst Lst) (setq Blk (tblobjname "block" Block)) (setq Next (entnext Blk)) (while Next (setq EntLst (entget Next)) (setq Lst (cons Next Lst)) (setq Next (entnext Next)) ); while (reverse Lst) ); function Thank you everyone for your help and I hope I do not need to bump this thread up again. Quote
Lee Mac Posted February 10, 2009 Posted February 10, 2009 Would you be able to upload the drawing of the actual block before insertion? I will see if I can write a LISP to extract coords. Quote
Olhado_ Posted February 10, 2009 Author Posted February 10, 2009 Would you be able to upload the drawing of the actual block before insertion? I will see if I can write a LISP to extract coords. Since you asked... Block Name: FGSE Looking for Layer "Bluebox". which is a "lwpolyline." Sample_Border_2000.dwg Quote
Lee Mac Posted February 10, 2009 Posted February 10, 2009 Here goes nothing... (defun c:GetThatBlueBox! (/ ss cEnt cEntLst vLst) (vl-load-com) (if (tblsearch "BLOCK" "FGSE") (progn (setq cEnt (tblobjname "BLOCK" "FGSE")) (while (setq cEnt (entnext cEnt)) (setq cEntLst (entget cEnt)) (if (and (eq "LWPOLYLINE" (cdadr cEntLst)) (eq "Bluebox" (cdr (assoc 8 cEntLst)))) (progn (setq vLst (mapcar 'cdr (vl-remove-if '(lambda (x) (/= 10 (car x))) cEntLst)) vLst (vl-sort vLst '(lambda (x1 x2) (< (car x1) (car x2)))) vLst (vl-sort vLst '(lambda (y1 y2) (< (cadr y1) (cadr y2))))) (alert (strcat "Coordinates of Diagonal:" (vl-princ-to-string (car vLst)) "," (vl-princ-to-string (last vLst)))))))) (princ "\n<< No Blue Box Block Found >>")) (princ)) Quote
Olhado_ Posted February 11, 2009 Author Posted February 11, 2009 Success. Thanks a lot you really saved me a lot of time. I also modified it a bit because we do have multiply borders, so now it cycles through all the blocks in the drawing looking for the block with the blue border. Of course, it lost the else statement since the top loop just happens to be a "While"; but in our cases everything we will use this for will have a border. But thanks again you definately did the hard part. (defun C:GetThatBlueBox! (/ ss cEnt cEntLst vLst nextblk) (vl-load-com) (setq nextblk (tblnext "BLOCK" T)) (while (/= nextblk nil) (setq cBlk (cdr (assoc 2 nextblk))) (if (tblsearch "BLOCK" cBlk) (progn (setq cEnt (tblobjname "BLOCK" cBlk)) (while (setq cEnt (entnext cEnt)) (setq cEntLst (entget cEnt)) (if (and (eq "LWPOLYLINE" (cdadr cEntLst)) (eq "Bluebox" (cdr (assoc 8 cEntLst)))) (progn (setq vLst (mapcar 'cdr (vl-remove-if '(lambda (x) (/= 10 (car x))) cEntLst)) vLst (vl-sort vLst '(lambda (x1 x2) (< (car x1) (car x2)))) vLst (vl-sort vLst '(lambda (y1 y2) (< (cadr y1) (cadr y2))))) (alert (strcat "Coordinates of Diagonal:" (vl-princ-to-string (car vLst)) "," (vl-princ-to-string (last vLst))))))))) (setq nextblk (tblnext "BLOCK")) ) (princ)) Quote
Lee Mac Posted February 11, 2009 Posted February 11, 2009 Glad it worked for you Olhado, was good to write a different LISP from the usual Quote
JohnM Posted February 11, 2009 Posted February 11, 2009 if you are just looking for the 4 points of a box try this (defun c:test () (vla-GetBoundingBox (vlax-ename->vla-object (car(entsel))) 'minpt 'maxpt);_check for heigth /width (setq llc (vlax-safearray->list minpt) urc (vlax-safearray->list maxpt) llc (list (car llc)(cadr llc)) urc (list (car urc)(cadr urc)) lrc (list (car urc)(cadr llc)) ulc (list (car llc)(cadr urc)) );_setq (setq pheight (distance llc ulc)) (setq pwidth (distance llc lrc)) );_defun Quote
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.