Jump to content

Recommended Posts

Posted

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..

Posted

By 'center point' do you mean the centre of the rectangular bounding box of the block?

Posted (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 by Lee Mac
  • Thanks 1
Posted

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.

Posted

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])))

Posted

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...

Posted
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?

Posted

50m on right side from block...and 90 degree is the angle of Xline...

Posted

Hi..

Anyone help me on this...

Posted

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
                   )
               )

  • Like 1
Posted

Hi Lee..

Thank you so much for your code.

Code is working what i want.

  • 10 months later...
Posted (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 by Pugazh
Posted

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?

  • Like 1
Posted (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 by Lee Mac
  • Thanks 1
Posted

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!

Posted

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 )

:beer:

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...