Author Topic: Create block from a specific layer objects  (Read 1354 times)

0 Members and 1 Guest are viewing this topic.

mohan

  • Newt
  • Posts: 98
Create block from a specific layer objects
« on: February 17, 2021, 09:47:59 AM »
Select all objects on a layer name called "North" & convert to block.
Base point of the block X,Y is (There is one circle object on the layer "North"), that is the base point of the circle's center X,Y
 :wideeyed:

Block Name: North (Choose)
Block unit: Metre  (Choose)
Scale uniformly: no tick (Choose)
« Last Edit: February 17, 2021, 09:51:45 AM by mohan »
"Save Energy"

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Create block from a specific layer objects
« Reply #1 on: February 17, 2021, 07:43:35 PM »
Removed incorrect post
« Last Edit: February 18, 2021, 05:43:04 PM by BIGAL »
A man who never made a mistake never made anything

mohan

  • Newt
  • Posts: 98
Re: Create block from a specific layer objects
« Reply #2 on: February 18, 2021, 02:55:00 AM »
Please check & correct it.....

Code: [Select]
(defun c:MyBlock ( / mybase myobjects )
  (setvar "cmdecho" 0)
  (setq mybase (ssget "x" '((0 . "CIRCLE")(8 . "North"))))
   Select circle & get center X,Y coord.??
  (setq myobjects (ssget "x" '((8 . "North"))))
    (command-s "_.Block" "North" mybase myobjects "")
    (command-s "_.Insert" "North" mybase "1.0" "1.0" "0.0")
    (setvar "cmdecho" 1)
    (princ)
)
"Save Energy"

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Create block from a specific layer objects
« Reply #3 on: February 18, 2021, 05:55:36 PM »
You can just do the ssget once, use repeat and look through the myobjects checking for a circle and if found then get centre point, then continue with make block.

Code: [Select]
(setq ent (entsel "Pick object for layer"))
(setq lay (cdr (assoc 8 (entget (car ent)))))
(setq mybase (ssget "X" (list (cons 8 lay))))
(repeat (setq x (sslength mybase))
(setq ent (entget (ssname mybase (setq x (- x 1)))))
(if (= (cdr (assoc 0 ent)) "CIRCLE")
(setq pt (cdr (assoc 10 ent)))
)
)
(command "-block" lay pt mybase "")
A man who never made a mistake never made anything

mohan

  • Newt
  • Posts: 98
Re: Create block from a specific layer objects
« Reply #4 on: February 20, 2021, 12:28:28 PM »
Ooh it is not clear enough !
My idea is to run a script with lisp & create the block, save then close the dwg. this is for my uncle who don't know block he has nearly 100 dwgs. I am going to help him, not to pick for a object to find the layer name

Code: [Select]
(setq ent (entsel "Pick object for layer"))
"Save Energy"

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Create block from a specific layer objects
« Reply #5 on: February 20, 2021, 03:11:49 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:MyBlock (/ p s c)
  2.   (setvar "cmdecho" 0)
  3.   (and (or (not (tblsearch "BLOCK" "North"))
  4.            (alert "Block name North is already existed <!>")
  5.            )
  6.        (or (setq p (ssget "_X" (list '(0 . "CIRCLE") '(8 . "North") (setq c (cons 410 (getvar 'CTAB))))))
  7.            (alert "No circle found to represent the base point of block <!>")
  8.            )
  9.        (or (setq s (ssget "_X" (list '(8 . "North") c)))
  10.            (alert "No objects found on layer name: North <!>")
  11.            )
  12.        (progn
  13.          (command-s "_.Block"  "North" "_none" (setq p (cdr (assoc 10 (entget (ssname p 0))))) s "")
  14.          (command-s "_.Insert" "North" "_none" p "1.0" "1.0" "0.0")
  15.          )
  16.        )
  17.   (setvar "cmdecho" 1)
  18.   (princ)
  19. )
  20.  

mohan

  • Newt
  • Posts: 98
Re: Create block from a specific layer objects
« Reply #6 on: February 21, 2021, 01:22:33 AM »
Thank you very much, your help is highly appreciated !
"Save Energy"