Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Help: Update insert block lisp

  1. #11
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,494
    Login to Give a bone
    0

    Default Re: Help: Update insert block lisp

    Quote Originally Posted by mhy3sx. View Post
    Opie is correct. Ted the points are allredy in the drawing, Your code insert point with givings number , not the DEH1.dwg to exist point number
    OOHHHH ok, now I understand.

    You want it to find an existing point with the number you provide, and place that "DEH1" block at the same insertion point of that point.
    Sorry for the confusion.

    Yes it will take a lot more than I have in my head

  2. #12
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,057
    Login to Give a bone
    0

    Default Re: Help: Update insert block lisp

    Maybe this will work.

    Code:
    (defun c:DEH (/ lPointList scl scl1 dt1 pnt pointsToList _:cmdecho _:doc)
      (defun *error* (msg)
        (setvar 'cmdecho _:cmdecho)
        (cond
          ((vl-position
             msg
             '("Function cancelled"
               "quit / exit abort"
               "console break"
               nil
              )
           )
          )
          ((princ (strcat "\nError: " msg)))
        )
        ;; Set undo mark end point
        (vla-endundomark _:doc)
        (princ)
      )
      (defun pointsToList (/           ssPoints    iCounter    ePoint
                           oPoint      aAttributes vAttributes oPointTag
                           sTag        lPoints     lCoord
                          )
        (setq ssPoints (ssget "X" '((0 . "INSERT") (2 . "POINT")))
              iCounter 0
        )
    
        (repeat (sslength ssPoints)
          (if (and (setq ePoint (ssname ssPoints iCounter))
                   (setq oPoint (vlax-ename->vla-object ePoint))
                   (setq iCounter (1+ iCounter))
                   (= (vla-get-hasattributes oPoint) :vlax-true)
                   (setq aAttributes (vla-getattributes oPoint))
                   (setq vAttributes (vlax-variant-value aAttributes))
                   (setq aAttributes (vlax-safearray->list vAttributes))
                   (setq oPointTag (car aAttributes))
                   (setq sTag (vla-get-textstring oPointTag))
                   (setq lCoord
                          (vlax-safearray->list
                            (vlax-variant-value (vla-get-insertionpoint oPoint))
                          )
                   )
              )
            (progn
              (setq
                lPoints (append lPoints
                                (list (cons sTag (list oPoint lCoord)))
                        )
              )
            )
          )
        )
        lPoints
      )
      ;; save reference to current doc
      (setq _:doc (vla-get-activedocument (vlax-get-acad-object)))
      (vla-startundomark _:doc)
      ;; Disable command echo
      (setq _:cmdecho (getvar 'cmdecho))
      (setvar 'cmdecho 0)
    
      (setq lPointList (pointsToList)
            scl        (getint "\n Set Scale (50,100,200,250,500,etc): ")
            scl1       (* scl 0.0025)
      )
      (while
        (progn (initget 128)
               (setq dt1 (getpoint "\n Specify point to insert the block: "))
        )
         (progn
           (cond ((and (= 'STR (type dt1))
                       (setq pnt (assoc dt1 lPointList))
                  )
                  (setq pnt (caddr pnt))
                 )
                 ((/= 'STR (type dt1))
                  (setq pnt dt1)
                 )
                 (t
                  (setq pnt nil)
                 )
           )
           (if pnt
             (command "_.insert" "DEH1" pnt scl1 scl1 0)
             (princ "\n ** Invalid number ** ")
           )
         )
      )
      (*error* nil)
    )
    Last edited by Opie; 2023-08-07 at 12:25 PM. Reason: tweaked per user request
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #13
    Member
    Join Date
    2023-03
    Posts
    19
    Login to Give a bone
    0

    Default Re: Help: Update insert block lisp

    Hi Opie, You did it ..it is working !!!!!

    I want to ask two things, if it is possible

    1) I test the code and I see that support only numbers. Sometimes I have letters and numbers for example k1,k2,s1 or 1N,3S .Is it possible to support them?

    and

    2)Is any way to merge these two codes in case to have an option

    Insert point ? [point / number] ;<-- to give the point number (like your code) or to pick a point (like the first code)


    The fist code


    Code:
        (Defun c:DEH ( / dt1 )
         (command "_layer" "_m" "DEH" "_c" "33" "" "")
         (setq olderr *error*
                 *error* at_err)
         (setvar "blipmode" 0)
         (setq osm (getvar "osmode"))
         (setvar "cmdecho" 0)
         (setq scl (getint "\n Set Scale (50,100,200,250,500,etc) :"))
         (setq scl1 (* scl 0.0025))
         (setq dt1 (getpoint "\n Select point to insert the block:"))
         (command "insert" "c:\\MBL\\DEH1.dwg" dt1 scl1 scl1 0)
         (setvar "cmdecho" 1)
         (setvar "blipmode" 1)
         (setvar "osmode" osm)
         (command "setvar" "clayer" "0")
        )

    Opie code

    Code:
    (defun c:DEH (/ lPointList scl scl1 dt1 pnt pointsToList)
      (defun pointsToList (/           ssPoints    iCounter    ePoint
                           oPoint      aAttributes vAttributes oPointTag
                           sTag        lPoints     lCoord
                          )
        (setq ssPoints (ssget "X" '((0 . "INSERT") (2 . "POINT")))
              iCounter 0
        )
    
        (repeat (sslength ssPoints)
          (if (and (setq ePoint (ssname ssPoints iCounter))
                   (setq oPoint (vlax-ename->vla-object ePoint))
                   (setq iCounter (1+ iCounter))
                   (= (vla-get-hasattributes oPoint) :vlax-true)
                   (setq aAttributes (vla-getattributes oPoint))
                   (setq vAttributes (vlax-variant-value aAttributes))
                   (setq aAttributes (vlax-safearray->list vAttributes))
                   (setq oPointTag (car aAttributes))
                   (setq sTag (vla-get-textstring oPointTag))
                   (setq lCoord
                          (vlax-safearray->list
                            (vlax-variant-value (vla-get-insertionpoint oPoint))
                          )
                   )
              )
            (progn
              (setq
                lPoints (append lPoints
                                (list (cons sTag (list oPoint lCoord)))
                        )
              )
            )
          )
        )
        lPoints
      )
    
      (setq lPointList (pointsToList)
            scl        (getint "\n Set Scale (50,100,200,250,500,etc): ")
            scl1       (* scl 0.0025)
            dt1        (getint "\n Specify point to insert the block: ")
      )
      (while (and dt1
                  (setq pnt (assoc (itoa dt1) lPointList))
                  (setq pnt (caddr pnt))
             )
        (progn
          (command "_.insert" "c:\\topocad\\MBL\\Σύμβολα\\DEH1.dwg" pnt scl1 scl1 0)
          (setq dt1 (getint "\n Specify point to insert the block: "))
        )
      )
      (princ)
    )
    Last edited by mhy3sx.; 2023-08-01 at 08:50 AM.

  4. #14
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,057
    Login to Give a bone
    0

    Default Re: Help: Update insert block lisp

    Yes it is possible. However, your original code does not actually select a block insert. It requests from the user to select a point. The returned value from the getpoint function (specified in the original code) returns a 3 element list representing the coordinates the user has picked. To allow the user to either enter a point number/string or pick a point in the drawing, the code would need to allow arbitrary input.

    To allow for a string instead of only a number, you would need to change the input to specify the point to either a getstring function or possibly the getpoint function if using the arbitrary input. I've revised my code above.
    Last edited by Opie; 2023-08-07 at 12:12 PM.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #15
    Member
    Join Date
    2023-03
    Posts
    19
    Login to Give a bone
    0

    Default Re: Help: Update insert block lisp

    Thank you Opie, works fine !!!!!!

  6. #16
    Member
    Join Date
    2023-03
    Posts
    19
    Login to Give a bone
    0

    Default Re: Help: Update insert block lisp

    Hi Opie, I find a bug in your code and i need help. If the block point exist in the drawing the code works fine, but some times I don't have points in my drawing and i need to insert a block and the code is not working (don;t insert block). Is any way to if the point block don't exist to let me insert the block (only by pick a point)?

    for example by giving an optiion

    Insert point ? [point / number]

    if i select point , the code works and without the point block ..... for multi times

    and

    if I choose number to work by giving the point number (only if point block exist) ... for multi times


    Thanks

  7. #17
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,057
    Login to Give a bone
    0

    Default Re: Help: Update insert block lisp

    I've revised my code above.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  8. #18
    Member
    Join Date
    2023-03
    Posts
    19
    Login to Give a bone
    0

    Default Re: Help: Update insert block lisp

    Hi Opie.I test your new code and I have this error

    Code:
    Error: bad argument type: lselsetp nil

    Thanks

  9. #19
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,057
    Login to Give a bone
    0

    Default Re: Help: Update insert block lisp

    I am not receiving this error during my testing using a drawing that already contains the DEH block. What steps are you doing to have this error occur?

    Have you determined what line of code is causing this?
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  10. #20
    Member
    Join Date
    2023-03
    Posts
    19
    Login to Give a bone
    0

    Default Re: Help: Update insert block lisp

    I create a new drawing without any block inside. I want this code to work in every drawing . If the drawing have the point block inside to have the option to insert the block by point number , if there is not a point block then insert the deh block by picking point. That's why i ask to have an optiion

    Insert point ? [point / number]

    if pick point -> then pick point (multy times)

    if pick number -> give point number (multy times)

    In your code is all together

    Thanks

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Need a help in modification of lisp. Please update the lisp code as required.
    By brahmanandam.thadikonda762224 in forum AutoLISP
    Replies: 0
    Last Post: 2018-09-20, 04:12 AM
  2. Replies: 1
    Last Post: 2017-01-15, 12:22 AM
  3. HELP......With Insert Block Lisp From Excel File
    By CADdancer in forum AutoLISP
    Replies: 1
    Last Post: 2013-06-25, 08:47 PM
  4. Replies: 27
    Last Post: 2006-10-06, 01:04 PM
  5. Replies: 19
    Last Post: 2006-03-14, 05:06 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
  •