Jump to content

Inserting blocks and attributes with LISP


Recommended Posts

Posted

I'm trying to hack (from some code that Lee and others have posted here) together a LISP that will insert a block of a door from a list. The door blocks need to have door numbers assigned to an attribute. In the list, I already have the block name and the door number. I have managed to get to the point where I can get the LISP to insert the block and start populating attributes, but I can't figure out how to make it stop adding attributes and move to the next block.

 

The help file refers to a SEQEND flag that should be what I need but I'm not sure how to code it.

 

The code in question is highlighted:

;;;******************************************************************************
;;;The hard parts of this code written by Lee Mac and posted on CADTutor.        
;;;Duct tape, baling twine and nails sticking out at odd angles                  
;;; holding that code together added by Glen Smith.                              
;;;                                                                              
;;;  http://www.cadtutor.net/forum/showthread.php?t=38230                        
;;;                                                                              
;;;Copyright October 2010                                                        
;;;                                                                              
;;;  The LISP takes a TEXT input file generated from AutoCAD's                   
;;;   Project - Export to spreadsheet - and inserts that block at the selected   
;;;   location. The Block must be in the search path.                            
;;;                                                                              
;;;  The input file is created by the export to spreadsheet function, and then   
;;;   opening the .xcl file and saving it as a .txt file. No other formating is  
;;;   required, sorting is optional but encouraged. Sort by BLOCKNAME and TAG.   
;;;                                                                              
;;;******************************************************************************
;;;                                                                              
(defun c:riserinsauto
      (/ file nl inslst Minp Maxp pts elst ipt xScale yScale rot entity count oldlayer )

  (vl-load-com)
  (setq xScale 1)
  (setq yScale 1)
  (setq rot 0)

  (defun StrBrk (str delim / pos lst)
     (while (setq pos (vl-string-position delim str))
        (setq lst (cons (substr str 1 pos) lst)
              str (substr str (+ pos 2))
        )
     )
     (reverse (cons str lst))
  )


  (defun RTD (a)                       ;radians to degrees function
     (/ (* a 180.0) PI)                ;takes angle in radians, returns angle in degrees
  )                                    ;end function RTD

  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-startUndoMark doc)
  (setq oldlayer (getvar "CLAYER"))

  (if (setq file (getfiled "Select Text File" (if *load *load "") "txt" 0))
        ;the file selected is stored in the GLOBAL variable *load and so defaults to the same filename in subsequent runs.
     (progn

        (setq *load file file  (open file "r"))
        (setq nl (read-line file))                 ;ignore first line of file, it's a header line
        (while (setq nl (read-line file))
           (setq entity (StrBrk nl 9))             ;entity should be a list of the entries on the nl
       (setq inslst (cons (nth 28 entity) inslst))      ;inslst gets the 29th entry from the exported spreadsheet list (the blockname)

        )

   (close file)

            (progn
              (setq inslst (reverse inslst))
          (setq ipt (getpoint "\nPick insertion point start: "))
          (setvar "CLAYER" "0")

          (foreach entity inslst
           (progn)
                  (if entity
             [color=red](command "-insert" entity ipt xScale yScale rot "GLEN")[/color]
            )
          (setq ipt (list (car ipt) (- (cadr ipt) 12) (caddr ipt)))
       )   
            )

      )
      (princ "\n<< No File Selected >>")
  )
  (setvar "CLAYER" oldlayer)
  (vla-EndUndoMark doc)
  (princ)
)

What happens is the first block gets inserted, gets "GLEN" as the first attribute and then the rest of the attributes get populated with subsequent command calls. attribute2 is "-insert" attribute 3 is the next block name and so on.

 

Thanks for any help you can offer.

 

Glen

Posted

I've only skimmed the code.

 

That said, what is the purpose of this line:

 

(foreach entity  inslst
         [color=red](progn)[/color]
         (if entity
           (command "-insert" entity ipt xScale yScale rot "GLEN")
           )
         (setq ipt (list (car ipt) (- (cadr ipt) 12) (caddr ipt)))
         )

 

 

This line:

 

(command "-insert" entity ipt xScale yScale rot "GLEN")

 

 

... inserts a block, and assigns "GLEN" as the first attribute value. *IF* I understand you correctly, there is more than one attribute for the block inserted, thus you're getting incorrect attribute values. Again *IF* that statement is true, then IMO - this line of code is where you should start.

 

If you want to terminate the attribute entries after adding "GLEN", then try adding a "" after "GLEN", like so:

 

(command "[color=red]._[/color]-insert" entity ipt xScale yScale rot "GLEN" [color=red]""[/color])

 

 

If you do want to 'fill in' additional values for other attributes, then you should add them in line, after "GLEN". Make sense?

Posted

RenderMan, thanks for looking.

 

The (progn) is an artifact from some code that was deleted, it too is now gone.

 

The blocks that I am inserting have many attributes, and different numbers of attributes, I am hoping that there is a way to just populate the first, and then go to the next block.

 

I tried adding the "" to the end of the insert statement, that leaves the attribute with its default value, but does not terminate the command.

 

looking up insert in the lisp help produces this from the DXF reference section:

Insert group codes
  Group code
 Description
  100
 Subclass marker (AcDbBlockReference) 
  [color=red]66[/color]
 [color=red]Variable attributes-follow flag (optional; default = 0); if  the value of attributes-follow flag is 1, a series of attribute entities is  expected to follow the insert, terminated by a [/color][color=red]seqend[/color][color=red]  entity[/color]
  2
 Block name
  10
 Insertion point (in OCS)
DXF: [i]X[/i] value; APP: 3D point

Which I take to mean that there exists a way to stop entering attributes and go to the next step, I just don't know what the SEQEND entity is. I have tried putting SEQEND where you suggested a pair of double quotes. This has the result of terminating the attribute entry AND the insertion such that the block is not inserted.

 

Thanks for looking.

Glen

Posted

I'll take another look using one of our title blocks (which has many attributes) later today.

 

I've got some submittals to get done first, and some training to attend, then I can hopefully help out.

Posted

I think I understand

 

(command "_.INSERT" block_name ins_pt x_scale y_scale rotation)
(while (> (getvar "CMDACTIVE") 0)
      (command ""))

 

This will fill in all attributes with their default values. -David

Posted

HAPPY HAPPY JOY JOY.

 

The code now works!! Many thanks, I will repost the working code after doing some housekeeping.

 

Glen

  • 3 years later...
Posted
HAPPY HAPPY JOY JOY.

 

The code now works!! Many thanks, I will repost the working code after doing some housekeeping.

 

Glen

 

can you repost? I am trying to do something similar with an equipment list...thanks!

  • 1 month later...
Posted
HAPPY HAPPY JOY JOY.

 

The code now works!! Many thanks, I will repost the working code after doing some housekeeping.

 

Glen

 

Hello Glen, I am very interested in your routine could put it on the forum?

Thanks.

Luis Augusto.

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...