Jump to content

LISP numbering stops working on blocks after express data import


shipmanlights

Recommended Posts

Hi I have a lisp that auto numbers attributes  in a multi attribute block by its tag. when I export and import the data back after editing it in excel, the lisp will not let me edit the blocks again. If I drop in the same block new in the same drawing it works fine on the new block. I don't get any errors on the command line. It just doesn't change the value.  I can still edit the blocks manually, but the lisp will not work. Any help is greatly appreciated. 

 

(defun c:numch ( / mode ss1 count emax count2 enext edata stop test num)
   (graphscr)
   (setvar "CMDECHO" 0)
   (setq mode (getvar "OSMODE"))           ;save osnap setting
   (setvar "OSMODE" 8)                     ;osnap mode to node
   (princ "\nSelect Instruments to Number...")
   (setq ss1 (ssget)                       ;selecting set of units
         count 0                           ;counting variable
         emax (sslength ss1)               ;number of units
   )                                       ;end setq
   (princ "\nEnter starting Channel Number...")
   (initget 7)
   (setq count2 (getint))                  ;number sequence

   (if (/= ss1 nil)                        ;loop
     (progn
       (while (< count emax)
         (setq ename (cdr (assoc -1  (entget (ssname ss1 count))))
               enext (entnext ename)
               edata (entget enext)
               test  (cdr(assoc 2 edata));finding attrib tag "CHANNEL"
               stop  (cdr(assoc 0 edata));finding "attrib"
         )                               ; end setq

         (while (/= stop "SEQEND") ;steping through unit attributes
           (if (= test "CHANNEL")     ;testing for attrib tag "CHANNEL"
             (progn               
               (setq num (itoa count2))
               (setq edata (subst (cons 1 num) 
                                  (assoc 1 edata) edata))               
                                  ;inserting unit number sequence
               (entmod edata)     ;update drawing database
             )                             ; end progn
           )                               ; end if
           (setq enext (entnext enext)     ; step through attrib entities
                 edata (entget enext)
                 test  (cdr(assoc 2 edata))
                 stop  (cdr(assoc 0 edata))
           )                               ; end setq
         )                                 ; end while
         (entupd ename)               ; update entity
         (setq count (1+ count))      ; next unit to insert number
         (setq count2 (1+ count2))    ; next unit number 
       )                              ; end while
     )                                ; end progn
   )                                  ; end if
   (setvar "OSMODE" mode)             ; reset osnap
   (prin1)
)                                     ; end defun

(defun fld (num)
   (cdr (assoc num d))
)

test2.dwg

Link to comment
Share on other sites

Don't think anything's wrong with your lsp. Maybe your in/export function doesn't release your blocks?

maybe this helps you to get a little bit more info :

 

(defun c:numch ( / mode ss1 count emax count2 ename enext edata stop test num found)
  (vl-load-com)(graphscr)(setvar "CMDECHO" 0)(setq mode (getvar "OSMODE"))(setvar "OSMODE")
  (princ "\nSelect Instruments to Number...")
  ;selecting only blocks with name "26 DEGREE S4"
   (setq ss1 (ssget '((0 . "INSERT")(2 . "26 DEGREE S4"))) found 0 count 0 emax (sslength ss1))
   (initget 7) (setq count2 (getint "\nEnter starting Channel Number..."));number sequence
   (if (/= ss1 nil);loop
     (progn
       (while (< count emax)
         (setq ename (cdr (assoc -1 (entget (ssname ss1 count))))
               enext (entnext ename) edata (entget enext)
               test  (cdr (assoc 2 edata));finding attrib tag "CHANNEL"
               stop  (cdr (assoc 0 edata));finding "attrib"
         )
         (if (not (vlax-write-enabled-p (vlax-ename->vla-object (ssname ss1 count))))
           (princ (strcat "\nBlock no. " (itoa count) " is locked")))
         (while (/= stop "SEQEND") ;steping through unit attributes
           (if (= test "CHANNEL")     ;testing for attrib tag "CHANNEL"
             (if (not (vlax-write-enabled-p (vlax-ename->vla-object enext)))
               (princ "Attribute 'CHANNEL' was locked")
               (progn
                 (setq found (1+ found) num (itoa count2) edata (subst (cons 1 num)(assoc 1 edata) edata))
                 (entmod edata))
             ); end if write-enabled
           ); end if attribute is 'channel'
           (setq enext (entnext enext) edata (entget enext) test  (cdr(assoc 2 edata)) stop (cdr(assoc 0 edata)))
         ); end while
         (entupd ename) (setq count (1+ count) count2 (1+ count2))
       ); end while
       (princ (strcat "\nNo. of channels updated : " (itoa found)))
     ); end progn
     (princ "\nNo blocks named '26 DEGREE S4' were selected")
   ); end if
   (setvar "OSMODE" mode)
   (princ)
)

Edited by rlx
Link to comment
Share on other sites

Hi Thank you for the reply.

I tried it and get an error. It works the same will work with new blocks inserted but will not edit/update anything that has been changed with a data import.  Something is definitely locked. I am using express tools attribute import/export. It does it when the information changes. Not the import export function.  I also have many block types that have the same tags. It effects them all.

 

 

 

Select Instruments to Number...
Select objects: 1 found
Select objects:
Enter starting Channel Number...500
No. of channels updated : 1; error: too many arguments
Command:
 

 

Link to comment
Share on other sites

Pasted the code here at home and noticed on the 2nd line a ) was missing. Having trouble when pasting the code at home to. something to do with code-page?

 (setvar "OSMODE" 8)

maybe that was the problem. Fixed it in above code but it's a small fix you can do yourself.

 

The drawing you posted , is it a drawing were the error occures? Else post a drawing after it was processed with express tools and generates the error.

Edited by rlx
Link to comment
Share on other sites

Hi;

That gets rid if the error, but it still doesn't update the data transferred block. It skips over it. It says it does in the command line. 

 

Select Instruments to Number...
Select objects: 1 found
Select objects: 1 found, 2 total
Select objects:
Enter starting Channel Number...200
No. of channels updated : 2"\nNo. of channels updated : 2"
Command

 

 

:skips.JPG.8c0d5151e5330de98657270b8d09e396.JPG

Link to comment
Share on other sites

I really can't reproduce your error... strange... regenall maybe? or try audit the drawing. Only other thing I could try is to re-write it to use vla-put-string etc instead of vanilla lisp. Or can you try on another computer to see if it has something to do with the autocad installation.

Link to comment
Share on other sites


(defun c:t1 ( / doc ss start-channel selset)
  (vl-load-com)(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (graphscr) (princ "\nSelect Instruments to Number...")
  ;selecting only blocks with name "26 DEGREE S4"
  (if (setq ss (ssget '((0 . "INSERT")(2 . "26 DEGREE S4"))))
    (progn
      (initget 7) (setq start-channel (getint "\nEnter starting Channel Number..."))
      (vlax-for blk (setq selset (vla-get-ActiveSelectionSet doc))
        (vl-some
          '(lambda (x)
             (if (eq "CHANNEL" (strcase (vla-get-tagstring x)))
               (progn (vla-put-textstring x (itoa start-channel)) (setq start-channel (1+ start-channel)))))
          (vlax-invoke blk 'getattributes)
        )
      )
    )
  )
  (if selset (vl-catch-all-apply 'vlax-release-object (list selset)))
  (vla-regen doc acActiveViewport)
  (princ)
)

 

Link to comment
Share on other sites

Awesome that unlocked it. Thanks! How would you change this to work will this work with all blocks? I have probably over 50 with the same attributes but are different block names and symbols. I also have to number them in selection order regardless of block type.

Link to comment
Share on other sites

You may need a lookup list blockname & tag name then it knows which attribute to update, the other way is making the attribute to be changed say the 1st, Pretty sure does not change visual appearance.

Link to comment
Share on other sites

just remove the blockname from the ssget function

    (setq ss (ssget '((0 . "INSERT"))))  

this will select all blocks , but only blocks with attribute 'channel' will be updated
 

Link to comment
Share on other sites

just for fun :

(defun c:t2 ( / i pt e) (vl-load-com) (graphscr) (initget 7) (setq i (getint "\nEnter starting Channel Number..."))
  (while (setq pt (getpoint "\nSelect Instrument to Number"))
    (if (and (setq e (nentselp pt))(vl-consp e)(= (length e) 4)(setq e (car (last e)))(= (cdr (assoc 0 (entget e))) "INSERT"))
      (vl-some '(lambda (x)(if (eq "CHANNEL" (strcase (vla-get-tagstring x)))(progn (vla-put-textstring x (itoa i))(setq i (1+ i)))))
        (vlax-invoke (vlax-ename->vla-object e) 'getattributes)))) (princ))
Edited by rlx
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...