Author Topic: Get the direction way of a Block  (Read 2666 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Get the direction way of a Block
« on: February 02, 2015, 07:57:30 AM »
Hello guys . :-)

I am looking for a way to know the direction of selected block according to its insertion point .

Attached a sample drawing of my daily used blocks .

Please help me

Coder

  • Swamp Rat
  • Posts: 827
Re: Get the direction way of a Block
« Reply #1 on: February 02, 2015, 11:37:19 AM »
it should be a challenge , isn't it ? :wink:

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Get the direction way of a Block
« Reply #2 on: February 02, 2015, 11:41:53 AM »
it should be a challenge , isn't it ? ;)

How are you going to apply this ? I'm having trouble seeing the benefit.
« Last Edit: February 02, 2015, 12:09:29 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CincyJeff

  • Newt
  • Posts: 89
Re: Get the direction way of a Block
« Reply #3 on: February 02, 2015, 11:48:11 AM »
Look at the insertion Scale X and Scale Y values and the rotation angle.

ChrisCarlson

  • Guest
Re: Get the direction way of a Block
« Reply #4 on: February 02, 2015, 12:09:07 PM »
I'm not sure of the purpose here...

Take the bottom right, if the flow was to be reversed, the block would be mirrored.

Actually, I'm not even sure of what's being asked  :-o

Coder

  • Swamp Rat
  • Posts: 827
Re: Get the direction way of a Block
« Reply #5 on: February 02, 2015, 12:48:19 PM »
Thank you guys for your replies .

I am after replacing any block of these ( Elbow Blocks or identical in that shape like Tee Y ) with another block, but the problem is if any block is mirrored , the result will be on the opposite side .  :-(

My needs is to replace a block with another having the same direction .

Many thanks for all  :-)

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Get the direction way of a Block
« Reply #6 on: February 02, 2015, 01:00:18 PM »
Why don't you redefine the block ? No need to worry about direction.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Coder

  • Swamp Rat
  • Posts: 827
Re: Get the direction way of a Block
« Reply #7 on: February 02, 2015, 01:07:45 PM »
Why don't you redefine the block ? No need to worry about direction.

Thank you for your interests in helping me .

I didn't get your idea  even after I opened your attached drawing . I am sorry .

EDIT: you might meant to redefine the the block to take a place of the old one ? no other solution ?  :-o
« Last Edit: February 02, 2015, 01:34:33 PM by Coder »

ChrisCarlson

  • Guest
Re: Get the direction way of a Block
« Reply #8 on: February 02, 2015, 01:53:54 PM »
Why not use something like this from Alan, select the new block, select the block to replace and it will match the original block rotation angle.

Code: [Select]
(defun c:BRE (/ *error* blk f ss temp)
  ;; Replace multiple instances of selected blocks (can be different) with selected block
  ;; Size and Rotation will be taken from original block and original will be deleted
  ;; Required subroutines: AT:GetSel
  ;; Alan J. Thompson, 02.09.10

  (defun *error* (msg)
    (and f *AcadDoc* (vla-endundomark *AcadDoc*))
    (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
      (princ (strcat "\nError: " msg))
    )
  )

  (if
    (and
      (AT:GetSel
        entsel
        "\nSelect replacement block: "
        (lambda (x / e)
          (if
            (and
              (eq "INSERT" (cdr (assoc 0 (setq e (entget (car x))))))
              (/= 4 (logand (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 e))))) 4))
              (/= 4 (logand (cdr (assoc 70 (entget (tblobjname "LAYER" (cdr (assoc 8 e)))))) 4))
            )
             (setq blk (vlax-ename->vla-object (car x)))
          )
        )
      )
      (princ "\nSelect blocks to be repalced: ")
      (setq ss (ssget "_:L" '((0 . "INSERT"))))
    )
     (progn
       (setq f (not (vla-startundomark
                      (cond (*AcadDoc*)
                            ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
                      )
                    )
               )
       )
       (vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*))
         (setq temp (vla-copy blk))
         (mapcar (function (lambda (p)
                             (vl-catch-all-apply
                               (function vlax-put-property)
                               (list temp p (vlax-get-property x p))
                             )
                           )
                 )
                 '(Insertionpoint Rotation XEffectiveScaleFactor YEffectiveScaleFactor
                   ZEffectiveScaleFactor
                  )
         )
         (vla-delete x)
       )
       (vla-delete ss)
       (*error* nil)
     )
  )
  (princ)
)

Code: [Select]
(defun AT:GetSel (meth msg fnc / ent good)
  ;; meth - selection method (entsel, nentsel, nentselp)
  ;; msg - message to display (nil for default)
  ;; fnc - optional function to apply to selected object
  ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC")))
  ;; Alan J. Thompson, 05.25.10
  (setvar 'errno 0)
  (while (not good)
    (setq ent (meth (cond (msg)
                          ("\nSelect object: ")
                    )
              )
    )
    (cond
      ((vl-consp ent)
       (setq good (if (or (not fnc) (fnc ent))
                    ent
                    (prompt "\nInvalid object!")
                  )
       )
      )
      ((eq (type ent) 'STR) (setq good ent))
      ((setq good (eq 52 (getvar 'errno))) nil)
      ((eq 7 (getvar 'errno)) (setq good (prompt "\nMissed, try again.")))
    )
  )
)

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Get the direction way of a Block
« Reply #9 on: February 02, 2015, 02:31:03 PM »
Why don't you redefine the block ? No need to worry about direction.
...
EDIT: you might meant to redefine the the block to take a place of the old one ? no other solution ?  :o

It seems like you're making this harder than it should be .. post an example of your new blocks.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Coder

  • Swamp Rat
  • Posts: 827
Re: Get the direction way of a Block
« Reply #10 on: February 03, 2015, 12:09:52 AM »
Why don't you redefine the block ? No need to worry about direction.
...
EDIT: you might meant to redefine the the block to take a place of the old one ? no other solution ?  :o

It seems like you're making this harder than it should be .. post an example of your new blocks.

You are right ronjonp , I don't know why I thought of it in that way , though the dxf 41 , 42 and 43 solved the problem even if the block is mirrored  :-(  thank you so much for your interests  :-)

Thank you ChrisCarlson for that program and for the author Alan J. Thompson , it works great  :-)

@ CincyJeff , I am sorry I did not get your point from the first time , but your answer was the one . many thanks  :wink:

Have a great day guys .