acad1985 Posted June 26, 2018 Share Posted June 26, 2018 Hi Everyone, I want to select a center point of block and place a XLine on Zero degree and 90 degree.. I can place it manually, but i have to so multiple times in my drawing..so that i want to do with lisp. Please help me.. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 26, 2018 Share Posted June 26, 2018 By 'center point' do you mean the centre of the rectangular bounding box of the block? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 26, 2018 Share Posted June 26, 2018 (edited) Here's a quick one using a lot of existing code - (defun c:blkxl ( / cen idx lst sel ) (if (setq sel (ssget '((0 . "INSERT")))) (repeat (setq idx (sslength sel)) (setq idx (1- idx) lst (LM:blockreferenceboundingbox (vlax-ename->vla-object (ssname sel idx))) ) (if (and lst (setq cen (mapcar '/ (apply 'mapcar (cons '+ lst)) '(4.0 4.0 4.0)))) (foreach vec '((1.0 0.0 0.0) (0.0 1.0 0.0)) (entmake (list '(000 . "XLINE") '(100 . "AcDbEntity") '(100 . "AcDbXline") (cons 10 cen) (cons 11 vec) ) ) ) ) ) ) (princ) ) ;; Block Reference Bounding Box - Lee Mac ;; Returns a WCS point list describing a rectangular frame bounding all geometry of a supplied block reference. ;; Excludes Text, MText & Attribute Definitions. ;; ref - [vla] Block Reference Object (defun LM:blockreferenceboundingbox ( ref ) ( (lambda ( lst ) (apply (function (lambda ( m v ) (mapcar (function (lambda ( p ) (mapcar '+ (mxv m p) v))) lst) ) ) (refgeom (vlax-vla-object->ename ref)) ) ) (LM:blockdefinitionboundingbox (vla-item (vla-get-blocks (vla-get-document ref)) (vla-get-name ref) ) ) ) ) ;; Block Definition Bounding Box - Lee Mac ;; Returns a WCS point list describing a rectangular frame bounding all geometry of a supplied block definition. ;; Excludes Text, MText & Attribute Definitions. ;; def - [vla] Block Definition Object (defun LM:blockdefinitionboundingbox ( def / llp lst urp ) (vlax-for obj def (cond ( (= :vlax-false (vla-get-visible obj))) ( (= "AcDbBlockReference" (vla-get-objectname obj)) (setq lst (append lst (LM:blockreferenceboundingbox obj))) ) ( (and (not (wcmatch (vla-get-objectname obj) "AcDbAttributeDefinition,AcDb*Text")) (vlax-method-applicable-p obj 'getboundingbox) (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'llp 'urp)))) ) (setq lst (vl-list* (vlax-safearray->list llp) (vlax-safearray->list urp) lst)) ) ) ) (LM:points->boundingbox lst) ) ;; Points to Bounding Box - Lee Mac ;; Returns the rectangular extents of a supplied point list (defun LM:points->boundingbox ( lst ) ( (lambda ( l ) (mapcar '(lambda ( a ) (mapcar '(lambda ( b ) ((eval b) l)) a)) '( (caar cadar) (caadr cadar) (caadr cadadr) (caar cadadr) ) ) ) (mapcar '(lambda ( f ) (apply 'mapcar (cons f lst))) '(min max)) ) ) ;; RefGeom (gile) ;; Returns a list which first item is a 3x3 transformation matrix (rotation, scales, normal) ;; and second item the object insertion point in its parent (xref, block or space) ;; Argument : an ename (defun refgeom ( ent / ang ang mat ocs ) (setq enx (entget ent) ang (cdr (assoc 050 enx)) ocs (cdr (assoc 210 enx)) ) (list (setq mat (mxm (mapcar '(lambda ( v ) (trans v 0 ocs t)) '( (1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0) ) ) (mxm (list (list (cos ang) (- (sin ang)) 0.0) (list (sin ang) (cos ang) 0.0) '(0.0 0.0 1.0) ) (list (list (cdr (assoc 41 enx)) 0.0 0.0) (list 0.0 (cdr (assoc 42 enx)) 0.0) (list 0.0 0.0 (cdr (assoc 43 enx))) ) ) ) ) (mapcar '- (trans (cdr (assoc 10 enx)) ocs 0) (mxv mat (cdr (assoc 10 (tblsearch "block" (cdr (assoc 2 enx)))))) ) ) ) ;; Matrix x Vector - Vladimir Nesterovsky ;; Args: m - nxn matrix, v - vector in R^n (defun mxv ( m v ) (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m) ) ;; Matrix Transpose - Doug Wilson ;; Args: m - nxn matrix (defun trp ( m ) (apply 'mapcar (cons 'list m)) ) ;; Matrix x Matrix - Vladimir Nesterovsky ;; Args: m,n - nxn matrices (defun mxm ( m n ) ((lambda ( a ) (mapcar '(lambda ( r ) (mxv a r)) m)) (trp n)) ) (vl-load-com) (princ) Edited May 5, 2019 by Lee Mac 1 Quote Link to comment Share on other sites More sharing options...
acad1985 Posted June 26, 2018 Author Share Posted June 26, 2018 Hi Lee Mac, This is amazing.. working perfectly. But i want it should be detect the Block and place the line automatically...(block selection by Block Name).. Thank you so much. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 27, 2018 Share Posted June 27, 2018 Make this change ([color=blue]if[/color] ([color=blue]setq[/color] sel ([color=blue]ssget[/color] '((0 . [color=maroon]"INSERT"[/color])[color=red](2 . "yourblockname")[/color]))) Quote Link to comment Share on other sites More sharing options...
acad1985 Posted June 27, 2018 Author Share Posted June 27, 2018 Thank you so much Bigal.. it's working.... If i want to add another one Xline on this (for Ex: i want to add one more Xline 50m from block in 90 degree),,,how can i do it...where i have to do the changes in lisp... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 27, 2018 Share Posted June 27, 2018 If i want to add another one Xline on this (for Ex: i want to add one more Xline 50m from block in 90 degree) 50m in which direction? Is the 90 degrees referring to the angle of the XLine or the direction of the offset? Quote Link to comment Share on other sites More sharing options...
acad1985 Posted June 27, 2018 Author Share Posted June 27, 2018 50m on right side from block...and 90 degree is the angle of Xline... Quote Link to comment Share on other sites More sharing options...
acad1985 Posted June 28, 2018 Author Share Posted June 28, 2018 Hi.. Anyone help me on this... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 28, 2018 Share Posted June 28, 2018 I would probably approach it like this: (foreach itm '( (( 0.0 0.0 0.0) (1.0 0.0 0.0)) (( 0.0 0.0 0.0) (0.0 1.0 0.0)) ((50.0 0.0 0.0) (0.0 1.0 0.0)) ) (apply '(lambda ( dsp vec ) (entmake (list '(000 . "XLINE") '(100 . "AcDbEntity") '(100 . "AcDbXline") (cons 10 (mapcar '+ cen dsp)) (cons 11 vec) ) ) ) itm ) ) 1 Quote Link to comment Share on other sites More sharing options...
acad1985 Posted June 30, 2018 Author Share Posted June 30, 2018 Hi Lee.. Thank you so much for your code. Code is working what i want. Quote Link to comment Share on other sites More sharing options...
acad1985 Posted June 30, 2018 Author Share Posted June 30, 2018 Thank you so much Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 30, 2018 Share Posted June 30, 2018 You're welcome Quote Link to comment Share on other sites More sharing options...
Pugazh Posted May 5, 2019 Share Posted May 5, 2019 (edited) Dear @Lee Mac, I need to move "XLINE" from the block center point. "90" degree in Horizontal direction & "180" degree in Vertical direction. Move distance is take from "DIMSCALE" Help me ! Edited May 5, 2019 by Pugazh Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 5, 2019 Share Posted May 5, 2019 Do you mean move the vertical xline in the positive x-direction, and move the horizontal xline in the negative y-direction, both by a distance equal to the DIMSCALE system variable? 1 Quote Link to comment Share on other sites More sharing options...
Pugazh Posted May 5, 2019 Share Posted May 5, 2019 Yes @Lee Mac Exactly ! i need this. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 5, 2019 Share Posted May 5, 2019 (edited) You can use a similar methodology as suggested in this post, but change the list of displacements & vectors to: (foreach itm (list (list (list (getvar 'dimscale) 0.0 0.0) '(0.0 1.0 0.0)) (list (list 0.0 (- (getvar 'dimscale)) 0.0) '(1.0 0.0 0.0)) ) (apply '(lambda ( dsp vec ) ... Edited May 5, 2019 by Lee Mac 1 Quote Link to comment Share on other sites More sharing options...
Pugazh Posted May 5, 2019 Share Posted May 5, 2019 Sorry @Lee Mac i just confused , I want this move the vertical xline in the negative x-direction, and move the horizontal xline in the positive y-direction, both by a distance equal to the DIMSCALE system. Sorry for the inconvenience! Quote Link to comment Share on other sites More sharing options...
Pugazh Posted May 5, 2019 Share Posted May 5, 2019 Thanks @Lee Mac I got it. (foreach itm (list (list (list (- (getvar 'dimscale)) 0.0 0.0) '(0.0 1.0 0.0)) (list (list 0.0 (getvar 'dimscale) 0.0) '(1.0 0.0 0.0)) ) (apply '(lambda ( dsp vec ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 5, 2019 Share Posted May 5, 2019 Good stuff - you're welcome! 1 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.