Jump to content

Changing / Converting Points into Blocks / Objects


highguyuk
 Share

Recommended Posts

Long time lurker and user of the site. Apologies my first post is a question rather than an answer :unsure: but now I’ve made the leap of faith who knows the possibilities! :D

 

I have a drawing with approx. 50 points in it. These points have been created from exporting a file from our MapInfo software into CAD format. Each of these points represents a feature (although everything contained within the drawing is just 1 feature) and I need to be able to attached a symbol (and then associated key) to define the feature when I xref in other similar drawings. I hope I described that ok.

 

After some searching, I’m led to believe I need to use an LSP command/file/code etc.? I have no knowledge of anything LSP based, how to use it or where to begin. The instructions I’ve seen in other threads asking similar questions unfortunately go straight over my head.

 

Could I ask is the LSP the only way to achieve my solution, and if so, is there a (very) basic step by step guide to using the LSP or could someone guide me through please? I understand that there is a need for full AutoCAD to perform this task – which I have access to if needbe.

Edited by highguyuk
Link to comment
Share on other sites

I guess there is no access with Lisp into LT cad version . Am I right ?

 

I mentioned this in the last line of my thread. My version I use regularly is AutoCAD LT 2011, although I have access to full AutoCAD within the company if I need to use it. So it is not a restriction. So fire away! =)

Link to comment
Share on other sites

I wrote basically what you want a few months ago...

 

(defun c:RPWB (/ *error* _blocks lst block ss space)
 ;; Replace Points With Block
 ;; Alan J. Thompson, 08.23.11
 ;; Required subroutine: AT:ListSelect

 (vl-load-com)

 (defun *error* (msg)
   (and *AcadDoc* (vla-endundomark *AcadDoc*))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (defun _blocks (doc / l)
   (vlax-for x (vla-get-blocks doc)
     (if (not (wcmatch (vla-get-name x) "*|*,`**"))
       (setq l (cons (vla-get-name x) l))
     )
   )
   (vl-sort l '<)
 )

 (vla-startundomark
   (cond (*AcadDoc*)
         ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
   )
 )

 (cond ((not (setq lst (_blocks *AcadDoc*))) (alert "Zero blocks in active drawing!"))
       ((and (setq block (car (AT:ListSelect "Select block to insert:" "" 10 10 "false" lst)))
             (princ "\nSelect POINT objects to replace: ")
             (ssget "_:L" '((0 . "POINT")))
        )

        (setq space (vlax-get-property
                      *AcadDoc*
                      (if (eq (getvar 'CVPORT) 1)
                        'PaperSpace
                        'ModelSpace
                      )
                    )
        )

        (vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*))
          (if (vla-insertblock space (vla-get-coordinates x) block 1. 1. 1. 0.)
            (vla-delete x)
          )
        )

        (vla-delete ss)
       )
 )
 (*error* nil)
 (princ)
)




(defun AT:ListSelect (title label height width multi lst / fn fo d item f)
 ;; List Select Dialog (Temp DCL list box selection, based on provided list)
 ;; title - list box title
 ;; label - label for list box
 ;; height - height of box
 ;; width - width of box
 ;; multi - selection method ["true": multiple, "false": single]
 ;; lst - list of strings to place in list box
 ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
 (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
 (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
                  (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
                  (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
                  (strcat "width = " (vl-princ-to-string width) ";")
                  (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
            )
   (write-line x fo)
 )
 (close fo)
 (new_dialog "list_select" (setq d (load_dialog fn)))
 (start_list "lst")
 (mapcar (function add_list) lst)
 (end_list)
 (setq item (set_tile "lst" "0"))
 (action_tile "lst" "(setq item $value)")
 (setq f (start_dialog))
 (unload_dialog d)
 (vl-file-delete fn)
 (if (= f 1)
   ((lambda (s / i s l)
      (while (setq i (vl-string-search " " s))
        (setq l (cons (nth (atoi (substr s 1 i)) lst) l))
        (setq s (substr s (+ 2 i)))
      )
      (reverse (cons (nth (atoi s) lst) l))
    )
     item
   )
 )
)

Link to comment
Share on other sites

Having tried this once with data, I have now tried to repeat on several drawings and I've developed an issue. When I am run the LSP, it moves the points. So it replaces the points with blocks but moves it to a different part of the drawing. I suspect the issue is to do with the block I'm creating, but I'm not sure.

 

It's annoying because I've already done this and had it working so I'm clearly doing something different - but struggling to pick what?!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...