Results 1 to 6 of 6

Thread: Move Block Insertion Point

  1. #1
    Active Member
    Join Date
    2013-06
    Posts
    72
    Login to Give a bone
    0

    Default Move Block Insertion Point

    Hello,

    I am new to scripting, and have zero knowledge of LISP. I would prefer to do everything in VBA, since it's a much more native language for me, but I am editing attributes with it and, after making an awesome tool to do everything I want, the text justification "bug" in ObjectDBX rears it's head (pretty angry I didn't notice this 36 hours ago). Now, normally I couldn't care, but in this case it has to look right.

    The only way I know to fix this error "quickly" is to remake my tool in C# (apparently) or open the drawings in editor and move the insertion point from where it is back to the same spot.

    I only have 4 block names that need to be fixed, and they're being inserted directly back to where they started. I am so clueless with LISP, I have no idea where to even start. Also, I have no idea even how to RUN these LISP routines on a bunch of drawings.

    Can anyone point me in the right direction? Should I use LISP? Can I do this more simply with some other kind of script I don't know about? I am using AutoCAD 2010 OR AutoCAD 2013 (prefer 2010).

  2. #2
    Active Member
    Join Date
    2013-06
    Posts
    72
    Login to Give a bone
    0

    Default Re: Move Block Insertion Point

    So, after some finagling, I think I had this working then somehow busted the syntax somewhere. I don't exactly understand how if statements work nor how they accept results as true or not. This is my code right now:
    Code:
    (defun c:blockmove ()
     (if(tblsearch "block" "blocka") ;if blocka exists, do this
      (progn
        (command "move" (ssget "X" '((0 . "INSERT")(2 . "blocka"))) 0,0,0 10,10,0)
      ) ; end progn
      (princ "\nNothing Changed") ;else this
     ) ; end if
    
     (cond ((tblsearch "block" "blockb") ; if blockb exists, do this
            (command "move" (ssget "X" '((0 . "INSERT")(2. "blockb"))) 0,0,0 10,10,0)
    	;(princ "\nTried to move blockb")
           )
           ((tblsearch "block" "blockc") ; if blockc exists, do this
            (command "move" (ssget "X" '((0 . "INSERT")(2 . "blockc"))) 0,0,0 10,10,0)
    	;(princ "\nTried to move blockc")
           )
           ((tblsearch "block" "blockd") ; if blockd exists, do this
            (command "move" (ssget "X" '((0 . "INSERT")(2 . "blockd"))) 0,0,0 10,10,0)
    	;(princ "\nTried to move blockd")
           (t
     	(princ "\nNo title information found; exiting!")
           )
     ) ; end cond
    (princ "Done")
    (princ)
    ) ; end defun
    blocka nearly always exists; it's existence is independent of the others (hence why is is an "IF" rather than a condition). blocks b, c and d are independent of each other; no more than one of them will exist at a time. I am sure there is a glaring error in this code, but I have built it from Google and have assuredly messed up syntax or simple logic.

  3. #3
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Move Block Insertion Point

    This one ?

    Code:
    (defun c:BlockMove (/ ss in)
      (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "blocka,blockb,blockc,blockd"))))
        (repeat (setq in (sslength ss))
          (vl-catch-all-apply
            'vla-move
            (list (vlax-ename->vla-object (ssname ss (setq in (1- in))))
                  (vlax-3d-point '(0. 0. 0.))
                  (vlax-3d-point '(10. 10. 0.))
            )
          )
        )
        (princ "\nNo title information found; exiting!")
      )
      (princ)
    )
    (vl-load-com)

  4. #4
    Active Member
    Join Date
    2013-06
    Posts
    72
    Login to Give a bone
    0

    Default Re: Move Block Insertion Point

    Thank you! My script looks pretty lame compared to the one you posted; works perfectly, even though I have no idea how it works, and that's absolutely fine by me.

  5. #5
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Move Block Insertion Point

    Quote Originally Posted by e_casagrande394681 View Post
    Thank you! My script looks pretty lame compared to the one you posted; works perfectly
    You're welcome .

    Quote Originally Posted by e_casagrande394681 View Post
    , even though I have no idea how it works, and that's absolutely fine by me.
    Not a problem , I will explain the code as best as I could .



    Quote Originally Posted by Tharwat View Post
    This one ?

    Code:
    (defun c:BlockMove (/ ss in)
      (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "blocka,blockb,blockc,blockd")))) ; if function would run if the first input is equal to true 
        (repeat (setq in (sslength ss)) ; if the first input is true , the repeat function would run according to the quantity of the selection set 
                                                  ; which the function sslength would return the quantity number in integer .
          (vl-catch-all-apply ; this important function would prevent the routine from throwing error if any of the selection set 's entities may on 
                                    ; lay on LOCKED layer , and the routine would pass that entity to the other one without a break down at all .
            'vla-move ; of course this is a move function and which is better than the use of command call in Lisp .
            (list (vlax-ename->vla-object (ssname ss (setq in (1- in)))) ; Here we converted the to VLA-OBJECT to be used by the vla-move function .
                  (vlax-3d-point '(0. 0. 0.)) ; this is origin point of the active document and converted to variant to be used by the vla-move function .
                  (vlax-3d-point '(10. 10. 0.)) ; this coordinate also converted as the previous one .
            )
          )
        )
        (princ "\nNo title information found; exiting!") ; This message would be print to the command line if the first statement 
                                                                                                ; by IF function did not meet any selectionset
      )
      (princ)
    )
    (vl-load-com) ; This function should be called when you use any of the vla- function to load the library for all related functions .
    Hope is clear and helpful .

  6. #6
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Move Block Insertion Point

    To save you a little work of having to convert your point to an array...

    Code:
    (defun c:BlockMove (/ ss i)
      (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "blocka,blockb,blockc,blockd"))))
        (repeat (setq i (sslength ss))
          (vl-catch-all-apply
            'vlax-invoke
            (list (vlax-ename->vla-object (ssname ss (setq i (1- i))))
                  'Move
                  '(0. 0. 0.)
                  '(10. 10. 0.)
            )
          )
        )
      )
      (princ)
    )
    (vl-load-com)

Similar Threads

  1. Insertion point not moving when using move action
    By M. Kubitza in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2009-10-30, 01:31 PM
  2. Dynamic Block and Insertion Point Help (Please)
    By DW2Whittle in forum VBA/COM Interop
    Replies: 1
    Last Post: 2009-01-29, 10:04 PM
  3. changing the insertion point of a block
    By brandenz in forum AutoCAD General
    Replies: 5
    Last Post: 2008-08-05, 04:39 PM
  4. Make insertion point move with scale action
    By KRISTIVETTE in forum Dynamic Blocks - Technical
    Replies: 9
    Last Post: 2006-06-01, 07:03 PM
  5. Move block insertion point
    By kitter in forum AutoLISP
    Replies: 2
    Last Post: 2005-07-04, 07:38 PM

Posting Permissions

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