Grid Setting

Grid Setting

piyush.parihar24
Advocate Advocate
1,696 Views
13 Replies
Message 1 of 14

Grid Setting

piyush.parihar24
Advocate
Advocate

Hi,

 

I have dozens of file with me in which the component/symbols are not on grid. I want to bring all of them on grid using LISP and it must also scoot the wires. Can advocates and experts help me with this?

0 Likes
Accepted solutions (1)
1,697 Views
13 Replies
Replies (13)
Message 2 of 14

pendean
Community Legend
Community Legend
Show us what you mean: post the problem DWG file and a "correct" DWG file for comparisons.
0 Likes
Message 3 of 14

syanchuck
Advocate
Advocate

Hi,

If you send me you drawing, I might be able to help you.

 

0 Likes
Message 4 of 14

piyush.parihar24
Advocate
Advocate

Please find the attachment for your reference.

0 Likes
Message 5 of 14

ВeekeeCZ
Consultant
Consultant

jpg is helpless. post what you'Ve been asked for - dwg.

0 Likes
Message 6 of 14

syanchuck
Advocate
Advocate

What are you looking for? You want just fix it manually or you are asking to create a LISP fixing it?

If you want to fix it manually, you need to use OSNAP and SNAP. 

0 Likes
Message 7 of 14

Kent1Cooper
Consultant
Consultant

Search the Forums for the word QUANTIZE.  There are some routines available that are designed to force things like Line endpoints, Circle centers, Block insertion points, Polyline vertices, etc. to coordinates at the nearest multiple of whatever increment you specify.  They probably won't do exactly what's in your image if you specify an increment the same as your grid, because there are grid points closer to some of the objects' original locations than where you show them ending up.  And the whole thing will be greatly affected by what those are -- if they're made up of separate pieces and not collected into Blocks, each separate piece will move to the nearest grid location, so their relationships will shift.  But some such routine could be a start.

Kent Cooper, AIA
0 Likes
Message 8 of 14

piyush.parihar24
Advocate
Advocate
I cannot share DWG as it will be against the ethics of company
Reference drawing will do?
0 Likes
Message 9 of 14

pendean
Community Legend
Community Legend
You can post the portion of the DWG that you showed in your screenshot: WBLOCK command.
0 Likes
Message 10 of 14

syanchuck
Advocate
Advocate

Hi I usually have to same problem, then I create a new demo drawing where I leave only necessary information.

One more issue for finding you the right solution: there are very few from that society are experts on electrical schematic / wiring diagrams. Most of  people here are mechanical / structure guys.

Anyways, let me know if you have a questions.

Message 11 of 14

Moshe-A
Mentor
Mentor
Accepted solution

@piyush.parihar24 ,

 

As others experts said, it's unclear what you want to do but here a 'Shot in the dark' 😀

attached is a command called GORD (Grid Order) to align blocks (you choose) onto a grid

as you will soon see, the real challenge here was not the align to grid but rather collecting the input for the process.

 

is this what you had in mind?

moshe

 

(vl-load-com)

; block grid order
(defun c:gord (/ getBlockName gridSpacing alignAngle applyRotation ; local functions
                 bname gs p0 p1 dir rot ss i AcDbBlkRef)

 (defun getBlockName (/ pick elist blk) 
  (while (not blk)
    (initget "Name")
    (setq pick (entsel (strcat "\n<Pick block>/Name"  (if (eq (getvar 'users1) "") ": " (strcat " <" (getvar 'users1) ">: ")))))

    (cond 
     ((eq (type pick) 'LIST)
      (setq elist (entget (car pick)))
      (if (eq (cdr (assoc '0 elist)) "INSERT")
       (setq blk (cdr (assoc '2 elist)))
       (progn
        (vlr-beep-reaction) 
        (setq blk (prompt "\nSelected object is not a block."))
       )
      )
     ); case
     ((not pick)
      (setq blk (getvar 'users1))
     ); case
     ((eq pick "Name")
      (if (eq (setq blk (getstring (strcat "\nEnter block name" (if (eq (getvar 'users1) "") ": " (strcat " <" (getvar 'users1) ">: "))))) "")
       (setq blk (getvar 'users1))
       (if (null (tblsearch "block" blk))
        (progn 
         (vlr-beep-reaction) 
         (setq blk (prompt (strcat "\nBlock " blk " is not exist.")))
        ); progn
       ); if
      ); if 
     ); case
    ); cond
  ); while

  blk
 ); getBlockName


 (defun gridSpacing (/ ask) 
  (if (not (setq ask (getdist (strcat "\nGrid spacing <" (rtos (getvar 'userr1) 2) ">: "))))
   (setq ask (getvar 'userr1))
   ask
  )
 ); gridSpacing


 (defun directionPath (/ ask) 
  (if (not (setq ask (getangle p0 (strcat "\nDirection path <" (rtos (getvar 'userr2) 2) ">: "))))
   (setq ask (getvar 'userr2))
   ask
  )
 ); gridSpacing
  

 (defun applyRotation ( / ask)
  (initget "Yes No")
  (if (not (setq ask (getkword "\nRotate block(s) about their base point <N>: ")))
   (setq ask "No")
   ask
  )
 ); applyRotation

  
 ; here start c:gord
 (vla-startUndoMark (vla-get-activedocument (vlax-get-acad-object)))
  
 (if (= (getvar 'userr1) 0.0)
  (setvar 'userr1 (car (getvar 'gridunit)))
 )  
  
 (if (and
       (/= (setvar "users1" (setq bname (getBlockName))) "")
       (setvar 'userr1 (setq gs (gridSpacing)))
       (setq p0 (getpoint "\nStarting base point: "))
       (setvar 'userr2 (setq dir (directionPath)))
       (setq rot (applyRotation))
       (setq ss (ssget (list '(0 . "insert") (cons '2 bname))))
       (setq i -1)
     )
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (setq AcDbBlkRef (vlax-ename->vla-object ename)) 
   (setq p1 (polar p0 dir (* (setq i (1+ i)) gs)))
   (vla-move AcDbBlkRef (vla-get-insertionPoint AcDbBlkRef) (vlax-3d-point (trans p1 0 1)))

   (if (eq rot "Yes")
    (vla-rotate AcDbblkRef (vla-get-insertionPoint AcDbBlkRef) dir)
   )
    
   (vlax-release-object AcDbBlkRef) 
  )
 ); if

 (vla-endundoMark (vla-get-activedocument (vlax-get-acad-object)))
 (princ) 
); gord

 

0 Likes
Message 12 of 14

Sea-Haven
Mentor
Mentor

A simple answer is to select the blocks, using the insertion points sort the order X & Y. Using bounding box can get size of block in particular as per example X width, then its a choice a gap or a fixed spacing from a point. Maybe later today will try to do something.

 

What is scoot wires.

0 Likes
Message 13 of 14

syanchuck
Advocate
Advocate

I am not familiar with creating videoclips, otherwise I would show how to get it done.

If someone can explain how to create a clip, I will volunteer to show you the process.

 

0 Likes
Message 14 of 14

Sea-Haven
Mentor
Mentor

This is like version 1 as a can it be done, at moment only does a gap between but could have more options like Horiz Vert and fixed spacing.

 

: pick blocks and arrange into equal spacing
; By AlanH March 2021

(defun c:blkeq ( / ent blkname obj pointmin pointmax minpoint maxpoint xdist ydist dist ss ins id lst pt)

(setq ent (entsel "\npick a block"))
(setq blkname (cdr (assoc 2 (entget (car  ent)))))

(setq obj (vlax-ename->vla-object (car ent)))
(vla-GetBoundingBox obj 'minpoint 'maxpoint)
  (setq pointmin (vlax-safearray->list minpoint))
  (setq pointmax (vlax-safearray->list maxpoint))
  (setq xdist (abs (- (car pointmin)(car pointmax))))
  (setq ydist (abs (- (cadr pointmin)(cadr pointmax))))
  
(setq dist (+ (getreal "\nEnter distance between blocks") xdist))

(setq ss (ssget (list (cons 0 "INSERT")(cons 2 blkname))))

(if (= ss nil)(progn (alert "You picked incorrect object not block\n \nWill now exit")(exit)))

(setq lst '())

(repeat (setq x (sslength ss))
  (setq ent (entget (ssname ss (setq x (- x 1)))))
  (setq ins (cdr (assoc 10 ent)))
  (setq id (cdr (assoc -1 ent)))
  (setq lst (cons (list (car ins)(cadr ins) id) lst))
)

(setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))

(setq pt (list (car (nth 0 lst))(cadr (nth 0 lst))))

(setq x 1)
(repeat (- (length lst) 1)
  (setq bpt (list (car (nth x lst))(cadr (nth x lst))))
  (setq pt (mapcar '+ pt (list dist 0.0 0.0)))
  (Command "move" (nth 2 (nth x lst)) "" bpt pt)
  (setq x (+ x 1))
)
(princ)
)

(c:blkeq)

 

screenshot355.png

0 Likes