+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 25
  1. #1
    Senior Member harilalmn's Avatar
    Computer Details
    harilalmn's Computer Details
    Operating System:
    Win XP
    Discipline
    Architectural
    harilalmn's Discipline Details
    Occupation
    CAD Manager
    Discipline
    Architectural
    Using
    AutoCAD 2010
    Join Date
    Aug 2010
    Location
    Bangalore, India
    Posts
    115

    Question Set Z Position of all Blocks to Zero

    Registered forum members do not see this ad.

    What is wrong in the code? I am trying to set the Z position value to zero for all the blocks in the drawing;

    Code:
    (defun c:B0()
      (setq myFilter(list (cons 0 "INSERT")))
      (setq ss (ssget "_X" myFilter))
      (setq l (sslength ss))
      (setq i 0)
      (Repeat l
        (setq blk (ssname ss i))
        (setq DXF (entget (car blk)))
        (setq IP (cadr (assoc 0 dxf)))
        (setq NewIP (subst "0" (caddr  IP) IP))
        (setq NewDXF (subst NewIP IP DXF))
        (entmod NewDXF)
      )
    )

  2. #2
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,106

    Default

    Code:
    (defun c:B0  ()
        (setq myFilter (list (cons 0 "INSERT")))
        (setq ss (ssget "_X" myFilter))
        (setq l (sslength ss))
        (setq i 0)
        (Repeat l
              (setq blk (ssname ss i))
              (setq DXF (entget blk))
              (setq IP (cdr (assoc 10 dxf)))
              (setq NewIP (subst 0.00 (caddr IP) IP))
              (setq NewDXF (subst (cons 10 NewIP) (assoc 10 dxf) DXF))
              (entmod NewDXF)
    (setq i (1+ i))
              )
        )
    variable i remains at 0.... "0" as string not real number...
    Among other things....
    Last edited by pBe; 5th Sep 2011 at 12:58 pm.

  3. #3
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,628

    Default

    Try this ...
    Code:
    (defun c:Test (/ ss i sset lst)
      (vl-load-com)
      (if (setq ss (ssget "_x" '((0 . "INSERT") (410 . "model"))))
        (repeat (setq i (sslength ss))
          (setq sset (ssname ss (setq i (1- i))))
          (setq lst (cons (vlax-ename->vla-object sset) lst))
        )
        (alert " << No Blocks existed in this drawing >>  ")
      )
      (foreach ml '(1e99 -1e99)
        (mapcar (function (lambda (x)
                            (vla-move x
                                      (vlax-3d-point (list 0 0 0))
                                      (vlax-3d-point (list 0 0 ml))
                            )
                          )
                )
                lst
        )
      )
      (princ)
    )

    Tharwat
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  4. #4
    Senior Member harilalmn's Avatar
    Computer Details
    harilalmn's Computer Details
    Operating System:
    Win XP
    Discipline
    Architectural
    harilalmn's Discipline Details
    Occupation
    CAD Manager
    Discipline
    Architectural
    Using
    AutoCAD 2010
    Join Date
    Aug 2010
    Location
    Bangalore, India
    Posts
    115

    Default

    pBe Thanks for your comment.. I now understand I should have added a (setq i (1+ i)) in the repeat loop...!!

    Thanks for the code Tharwat...!! That was much professional a solution compared to my code...!!

    Happy Happy....

  5. #5
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,106

    Default

    Code:
    ....
    (1e99 -1e99).....
    Interesting

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,732

    Default

    I would approach it this way:

    Code:
    (defun c:B0 ( / e i p s )
        (if (setq s (ssget "_X" '((0 . "INSERT") (-4 . "*,*,<>") (10 0.0 0.0 0.0))))
            (repeat (setq i (sslength s))
                (setq e (entget (ssname s (setq i (1- i))))
                      p (assoc 10 e)
                )
                (entmod (subst (list 10 (cadr p) (caddr p) 0.0) p e))
            )
        )
        (princ)
    )
    I don't see the need to move everything to 1e99 elevation and back just to set the elevation to zero
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    Using (subst) on a point value is very dangerous

    (setq ip '(10 10 10 10))
    (subst 0 (caddr ip) ip)

    Returns -> '(0 0 0 0)


    Code:
    (defun c:iz0 (/ ss en ed in)
    
      (and (setq ss (ssget "X" '((0 . "INSERT"))))
           (while (setq en (ssname ss 0))
                  (setq ed (entget en)
                        in (cdr (assoc 10 ed)))
                  (entmod (subst (list 10 (car in) (cadr in) 0.0)
                                 (assoc 10 ed) ed))
                  (entupd en)
                  (ssdel en ss)))
    
      (prin1))
    I would think a lot more filtering would be advisable. Maybe groups 67 210 at the very least should be added.

    Also this will not move the attributes the elevation 0.

    -David
    R12 (Dos) - A2K

  8. #8
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,106

    Default

    or Ctrl+1
    Quick Select
    Position Z

  9. #9
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,628

    Default

    Quote Originally Posted by pBe View Post
    Code:
    ....
    (1e99 -1e99).....
    Interesting
    Thanks pBe .

    Quote Originally Posted by Lee Mac View Post

    I don't see the need to move everything to 1e99 elevation and back just to set the elevation to zero
    Why not ?

    Would that harm or incorrect in away or another ?

    Tharwat
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  10. #10
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,628

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by harilalmn View Post
    [B]

    Thanks for the code Tharwat...!! That was much professional a solution compared to my code...!!

    Happy Happy....
    You're welcome harilalmn .

    Enjoy it buddy

    Tharwat
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

Similar Threads

  1. Sustain position of Annotative Blocks after a Move
    By StykFacE in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 3
    Last Post: 5th Jan 2010, 05:15 pm
  2. exploding nested blocks and losing position
    By leesutto in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 10
    Last Post: 18th Dec 2009, 06:19 pm
  3. sun position
    By rookie37 in forum AutoCAD 3D Modelling & Rendering
    Replies: 1
    Last Post: 22nd Nov 2009, 03:47 pm
  4. XREF Position
    By drayle in forum AutoCAD Beginners' Area
    Replies: 8
    Last Post: 23rd Sep 2009, 11:18 pm
  5. From dtext to a z-position
    By Veryname in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 23rd Jan 2009, 07:21 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts