Jump to content

Inserting multiple blocks


Luís Augusto

Recommended Posts

 

Here is a suggestion.

 

Prompt: Specify insertion point:

Then specific ...

Next

 

Prompt: Specify insertion point:

Then specific ...

Next

 

Until it runs out the possibilities ...

 

Tharwat Hello, how are you?

 

I bring good news. :D

 

I believe that the function created by Lee Mac "Unique & Duplicate List Functions", solves the issue of generating a list of distinct names, required for program offer me the names for inserting blocks.

 

Unfortunately I am not at all near the knowledge you have with autoLisp, otherwise I'd do the implementation of the code. That does not mean I'm not trying to, but if I do, will be more luck than skill.

 

I was forced to interrupt my studies in that language in the past for serious personal reasons. Now I intend to go back to my studies and I do not stop until I become Self-Sufficient.

 

Thank you for your help.

 

A big hug.

 

Regards, Luís Augusto.

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Luís Augusto

    13

  • Tharwat

    10

  • BIGAL

    1

  • Bhull1985

    1

Top Posters In This Topic

Posted Images

All the best Luis .

 

I hope that you would post the final codes here which I believe that many people would get the benefit of it ;)

 

Surely I will post the code Tharwat.

 

As I mentioned in post 3, there was a solution to the case but was not shared. I'll never do something like that. I'm not the author of the code, I'm just an apprentice who hopes to be helped again.

Link to comment
Share on other sites

First I must thank the great friend Tharwat who devoted his free time to write this wonderful code.

Thank you for always supporting me, I have great admiration for his work.

 

I must also thank the great Lee Mac that on your site provides many functions and tutorials that greatly facilitate the learning of novice like me.

 

I hope one day I can help others as I am helped here in this forum.

 

I made minor changes to the program for it to work as my need.

 

Thanks to everyone who participated in this post. Feel free to modify or improve the code.

 

If want to test:

 

Sample Conectors.zip

POPULATE ATTRIBUTES.csv

 

Remember:. The comma "," should be replaced by semicolons ";" depending on region.

 

translated by google translate

 

(defun c:Test (/ *error* Deconstruct_String right left con1 con2 xl ok o st l lst a b c d f fp bn p go vl name ch insertList)
 ;;                    ;;
 ;;    Author : Tharwat Al Shoufi    ;;
 ;;                    ;;
 (or doc (setq doc (vla-get-activedocument (vlax-get-acad-object))))
 (defun *error* (u)
   (if ch
     (setvar 'CMDECHO ch)
   )
   (princ "\n*Cancel*")
 )

 (defun Deconstruct_String (st delimiter / p l)
   (while (setq p (vl-string-search delimiter st 0))
     (setq l  (cons (substr st 1 p) l)
           st (substr st (+ p 2) (strlen st))
     )
   )
   (if st
     (setq l (cons st l))
   )
   (setq l (reverse l))
 )

 (if (setq xl (getfiled "Select the required Excel file :" (getvar 'DWGPREFIX) "csv" 16))
   (progn (setq ok t
                ch (getvar 'CMDECHO)
                o  (open xl "r")
          )
          (setvar 'CMDECHO 0)
          (while (setq st (read-line o))
            (setq l   (cons (setq st (Deconstruct_String st ",")) l) ;The comma "," should be replaced by semicolons ";" depending on region.
                  lst (cons (strcase (car st)) lst)
            )
          )
     
     (setq insertList (LM:Unique LST)) ;Modification 25/01/2014
     
          (close o)
   )
   (setq ok nil)
 )
 

 (foreach blk insertList ;Modification 25/01/2014
 (if (and ok
          (/= (setq bn blk) "")
          (if (member (setq bn (strcase bn)) lst)
            t
            (progn (alert "Block name is not included in the Excel file <!>") nil)
          )
          (if (not (tblsearch "BLOCK" bn))
            (if (setq fp (findfile (strcat bn ".dwg")))
              (progn (command "_.-insert" fp nil) t)
              (progn (alert "Block Name is not found in Support Folder <!>") nil)
            )
            t
          )
     )
   (progn (setvar 'CMDECHO ch)
     (vla-StartUndoMark doc)
          (setq p (getpoint (strcat "\n Specify insertion point: " blk))) ;Modification 25/01/2014
            (setq vl (vla-insertblock (vla-get-block (vla-get-activelayout doc)) (vlax-3d-point p) bn 1.0 1.0 1.0 0.)) ;Modification 25/01/2014
            (foreach x (vlax-invoke vl 'getattributes)
              (foreach tg l
                (if (and (eq (car tg) (strcase bn)) (eq (strcase (vla-get-tagstring x)) (cadr tg)))
                  (vla-put-textstring x (caddr tg))
                )
              )
          )
          
     (vla-EndUndoMark doc)
   )
 )
 )  
 (princ "\nAll blocks were successfully inserted.") ;Modification 25/01/2014
 (princ)
)
(vl-load-com)

;; Unique  -  Lee Mac
;; Returns a list with duplicate elements removed.

(defun LM:Unique ( l / x r )
   (while l
       (setq x (car l)
             l (vl-remove x (cdr l))
             r (cons x r)
       )
   )
   (reverse r)
)

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.


×
×
  • Create New...