Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Using "-insert" with attributes in a loop

  1. #1
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Using "-insert" with attributes in a loop

    Hi,

    Could anybody help me get this to work? (without laughing if its blatantly obvious)

    Code:
    (while 
       (vl-cmdf "-INSERT" (vla-get-name  BlkObj) PAUSE "1" "1" PAUSE)
        (if (<= TxtNum 9)
    	(setq BlkTxt (strcat TxtPre "0" (itoa TxtNum)))
    	(setq BlkTxt (strcat TxtPre (itoa TxtNum)))
          )
        (setq NewBlkObj (vlax-ename->vla-object (entlast)))
          (vla-put-textstring
    	(nth 0
    	     (vlax-safearray->list
    	       (variant-value
    		 (vla-getattributes NewBlkObj)
    	       )
    	     )
    	)
    	BlkTxt
          )
     (setq TxtNum (1+ TxtNum))
        )
    Thanks in advance

  2. #2
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Using "-insert" with attributes in a loop

    Quote Originally Posted by jmcshane View Post
    Hi,

    Could anybody help me get this to work? (without laughing if its blatantly obvious)

    Code:
    (while 
       (vl-cmdf "-INSERT" (vla-get-name  BlkObj) PAUSE "1" "1" PAUSE)
        (if (<= TxtNum 9)
        (setq BlkTxt (strcat TxtPre "0" (itoa TxtNum)))
        (setq BlkTxt (strcat TxtPre (itoa TxtNum)))
          )
        (setq NewBlkObj (vlax-ename->vla-object (entlast)))
          (vla-put-textstring
        (nth 0
             (vlax-safearray->list
               (variant-value
             (vla-getattributes NewBlkObj)
               )
             )
        )
        BlkTxt
          )
     (setq TxtNum (1+ TxtNum))
        )
    Thanks in advance
    probably not without some more information. What is it supposed to do? There appear to be some variables that are not defined in your segment of code, their meaning would be important to getting the function to work properly

  3. #3
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Using "-insert" with attributes in a loop

    A trick I usually use to check if a command has completed is to check the CMDACTIVE and / or CMDNAMES sysvars. This way you could know that -INSERT is still asking for data (if you have ATTREQ=1) without knowing how many ATTRIBS are in the block.this is if you still want to use the (command ...) interface.

    If you want to do the same thing as your code, but not use the vla extensions the normal entlast, entnext, entget & entmod after the -INSERT does the same thing as the vla functions you're using without the back-and-forth between LISP and ActiveX.

    Something like:
    Code:
    (setq atdata (entget (entnext (entlast))))
    (setq atdata (subst (cons 1 BlkTxt) (assoc 1 atdata) atdata))
    (entmod atdata)
    (entupd (entlast))

  4. #4
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Re: Using "-insert" with attributes in a loop

    The big picture is that I am trying copy a block with a single attribute and have the attribute increase by 1 every time I copy it.

    What I can't seem to do is end the loop.

    ;Get user to enter Prefix if there is one. eg TP
    ;Get user to enter the first number in the sequence
    ;If the first number is between 1 and 9, stick a 0 in front of it.
    ;Select the block with the attribute
    ;Check that it has an attribute
    ;And then, keep copying the block and increasing the attribute by 1.

    I was using the vla-copy and vla-move which did work but the problem was that I could not see the block in relation to the previous one untill after it was placed.




    Code:
    (defun c:Copya ()
      (vl-load-com)
      (setq	AcadObject (vlax-get-Acad-Object)
    	ActiveDoc  (vla-get-ActiveDocument AcadObject)
    	util	   (vla-get-utility ActiveDoc)
      )
    
      (setvar "ATTREQ" 0)
      
      (setq	TxtPre (strcase (getstring "\nEnter Prefix :"))
    	TxtNum (getint "\nEnter First number :")
      )
      (if (<= TxtNum 9)
        (setq BlkTxt (strcat TxtPre "0" (itoa TxtNum)))
        (setq BlkTxt (strcat TxtPre (itoa TxtNum)))
      )
    
      (setq	BlkObj	 (vlax-ename->vla-object
    		   (car (entsel "\nPlease Select a Block to copy :"))
    		 )
    	InsPoint (vla-get-insertionpoint BlkObj)
      )
    
      (if (= (vla-get-hasattributes BlkObj) :vlax-true)
        (vla-put-textstring
          (nth 0
    	   (vlax-safearray->list
    	     (variant-value
    	       (vla-getattributes BlkObj)
    	     )
    	   )
          )
          BlkTxt
        )
        (alert "Selected Block Does Not Have Any Attributes !")
      )
    
      (while
       (vl-cmdf "-INSERT" (vla-get-name  BlkObj) pause "1" "1" pause)
        (setq TxtNum (1+ TxtNum))
        (if (<= TxtNum 9)
    	(setq BlkTxt (strcat TxtPre "0" (itoa TxtNum)))
    	(setq BlkTxt (strcat TxtPre (itoa TxtNum)))
          )
        (setq NewBlkObj (vlax-ename->vla-object (entlast)))
          (vla-put-textstring
    	(nth 0
    	     (vlax-safearray->list
    	       (variant-value
    		 (vla-getattributes NewBlkObj)
    	       )
    	     )
    	)
    	BlkTxt
          )
        
        )
    (setvar "ATTREQ" 1)
    )
    Attached Files Attached Files

  5. #5
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Using "-insert" with attributes in a loop

    In this case you could use this, it doesn't exactly do what you wanted. But, it does increment pic picking text / attributes and allows for a minimum number of digits (i.e. 001, 002, ...., 009, 010, 011, ... , 099, 100, 101, ...). Maybe you could use the code to implement your utility.
    Attached Files Attached Files

  6. #6
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Re: Using "-insert" with attributes in a loop

    Quote Originally Posted by irneb View Post
    In this case you could use this
    That is a very neat trick. It'll take me a week to study all of that!


    I think my main problem is just getting the loop to work though.

    Many Thanks


    John

  7. #7
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Using "-insert" with attributes in a loop

    I didn't really mean it like that ... you could use this after copying the blocks.

    If you simply want to have the loop stop if the user doesn't specify a point, then you need to obtain that point 1st, not during the actual command call. Something like:
    Code:
    ;; Replace your (while (vl-cmdf ...) with this
    (setq ang 0.0)
    (while (and ang (setq pt (getpoint "Pick insertion point: ")))
      (if (setq ang (getangle pt (strcat "Pick rotation <" (rtos ang) ">: ")))
        (progn
          (setq ang (* 180.0 (/ pi ang))) ;Convert Radians to Degrees
          (vl-cmdf "-INSERT" (vla-get-name  BlkObj) pt "1" "1" ang)
          ;; Continue the rest of your code inside the while
        )
      )
    )
    Now if the user stops selecting a point, the pt is SETQed ti nil so the loop stops. And if the user doesn't specify an angle the loop also stops.

  8. #8
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Using "-insert" with attributes in a loop

    Sorry, I screwed up a bit, my radians to degrees convert was wrong. And after some thought I noticed that if the user doesn't specify an angle - the default should be used . So here's the correct one:
    Code:
    (setq ang 0.0)
    (while (setq pt (getpoint "Pick insertion point: "))
      (if (setq ang1 (getangle pt (strcat "Pick rotation <" (rtos ang) ">: ")))
        (setq ang (* 180.0 (/ ang1 pi)))
      ) ;_ if
      (vl-cmdf "-INSERT" (vla-get-name BlkObj) pt "1" "1" ang)
      ;; Continue the rest of your code inside the while
    ) ;_ while

  9. #9
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Re: Using "-insert" with attributes in a loop

    Thanks irneb,

    Yes that does work fine, but I really need to see the block in relation to the previous one before I pick the insertion point.

    The particular point I have for this routine is I might have a sewer line that goes on for a few miles in any direction and I need to break it down into individual sheets. And with that code that you gave me, and the code I had myself using the vla-copy and vla-move, I don't actually get to see the block untill after it has been inserted. So, while inserting the block representing the sheet,it might not actually overlap the previous one. I won't know untill after it has been inserted.

    Thanks for your time and patience.

    John

  10. #10
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Using "-insert" with attributes in a loop

    Try this:
    Code:
    (while (or (command "-INSERT" (vla-get-name  BlkObj) (setq pt (getpoint)) "1" "1" pause) pt)
      (if pt
        (progn
          ;; Your code
        )
      )
    )
    Used the (command function instead of the vl-cmdf, so the command executes as and when you ask for the point, not after you've already gotten the point. I think this is what you wanted.

Page 1 of 2 12 LastLast

Similar Threads

  1. "Loop" and "Infinite" playback in animator and timeliner
    By 6adworld in forum NavisWorks - General
    Replies: 2
    Last Post: 2010-04-11, 07:04 PM
  2. if filter text equals "*" insert block "*"
    By d_m_hopper in forum AutoLISP
    Replies: 6
    Last Post: 2009-04-24, 05:46 PM
  3. Improve "Close Loop" in Sketches
    By inventor.wishlist1738 in forum Inventor Wish List
    Replies: 0
    Last Post: 2009-02-08, 11:31 PM
  4. Save command creates "Done" loop in certain DWG files
    By Chris.N in forum AutoCAD General
    Replies: 2
    Last Post: 2007-01-24, 10:38 PM
  5. Replies: 1
    Last Post: 2006-06-13, 06:36 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
  •