Author Topic: Update Drawings with Blocks and Attīs  (Read 1585 times)

0 Members and 1 Guest are viewing this topic.

Soui21

  • Guest
Update Drawings with Blocks and Attīs
« on: October 30, 2016, 12:46:46 PM »
Hi Forum,

i try to push my 2D Workflow with some Lisp Routines.

The following Routine imports new Blocks with filled out Attributes multiple times from an txt File. Works fine so far.

But i have some questions. I use the German Version of ACAD so...
1. After the routine is finished a message comes up in the console "; Fehler: Fehlerhafter Argumenttyp: stringp nil" Whereīs the Problem? I did not find anything. The Routine works as i wish.
2. How can i use Chars in a String e.g. ä,ü. and so on? see this row (command "layer" "m" "BLOCKS" "FA" "T" "0,255,0" "" "L" "Continuous" "" "") i have to define the colour in RGB, because it dont work with "GRÜN" for green
3. What i have to do, to insert a block from a Folder on my hdd, and not from my existing blocks in my drawing?
4. What i have to do, to update blockattributes or Blocks if something has changed in my txt file
5. What i have to do, to use the table entities from a sql db and not from a txtfile?

Thanks a lot!


Code - Auto/Visual Lisp: [Select]
  1. ;~******************************************************************************
  2. ;~* FILE NAME:BLOCKSIN.lsp
  3. ;~* FUNCTION: INSERT BLOCKS WITH ATTRIBUTES INTO DRAWINGS AND FILL ATTRIBUTES
  4. ;~* WRITTEN BY: SOUI21
  5. ;~* REVISIONS:  Version Alpha:
  6. ;~******************************************************************************
  7.  
  8. (defun C:BLOCKSIN ()
  9.  
  10. (setvar "cmdecho" 0)
  11. ;#1a----------- layer layer & text & text settings settings   ------------
  12. ;create and set ;create and set layer layer to blocks to blocks - create romans text style
  13. (command "layer" "m" "BLOCKS" "FA" "T" "0,255,0" "" "L" "Continuous" "" "")
  14. (command "stil" "romans" "romans" "0.125" "1" "" "" "" "")
  15.  
  16.  
  17. ;#1b----------- DEFINING VARIABLE SETTINGS
  18.  
  19. ; capture user settings
  20. (setq smd (getvar "osmode")) ;osnap setting
  21. (setq arq (getvar "attreq")) ;attribute request
  22. (setq atd (getvar "attdia")) ;attribute dialog box
  23.  
  24. ; change to what settings need to be
  25. (setvar "osmode" 0) ;osnap to none
  26. (setvar "attreq" 1) ;ask for attribute values on insert
  27. (setvar "attdia" 0) ;issues command prompts for data
  28.  
  29. ;set starting points for inserts and not nil
  30. (setq xval 1.0) ;initial x
  31. (setq yval 30.0) ;initial y
  32. (setq eqdata "notnil") ;dummy variable
  33.  
  34. (command "zoom" "all")
  35. ;prompt user for the location of the data file
  36. (princ "\n Please Enter Name of Data File - Include the path and extension")
  37. (princ "\n")
  38. (setq eqdataf (strcase (getstring "\n Data File = ")))
  39.  
  40. ;#3----------- *** while motor data ***
  41. (setq eqdatal (open eqdataf "r")) ;open data file
  42.  
  43. (while (/= eqdata nil) ;while data continue
  44.   (setq eqdata (read-line eqdatal)) ;read new line of data
  45.   (setq eqdatac (strcase eqdata)) ;change to upper case
  46.  
  47.   (setq eqdat (sparse eqdatac ";"))
  48. ;#3a---------- do not do not change anything 3 - 3a
  49.  
  50. (setq EQPID (nth 0 eqdat) ;EQUIPMENT ID
  51.       EQTAG (nth 1 eqdat) ;TAG
  52.       NEWIO (nth 2 eqdat) ;DESCRIPTION
  53.       BN (nth 3 eqdat) ;BLOCKNAME
  54.  
  55. ) ;end setq
  56.  
  57. ;insert tag & text
  58.  
  59. (setq blkinpnt (list xval yval)) ;create xy insert point for tag
  60.  
  61.   (command "_insert" BN blkinpnt "1" "" "" EQPID EQTAG NEWIO)
  62. ;set new point
  63.   (setq yval (- yval 30.0)) ;y Point
  64.  
  65.   (if (< yval -300.0)
  66.    (PROGN
  67.      (setq yval 30.0)
  68.      (setq xval (+ xval 30.0))
  69.    )
  70.    (setq  SIXPACK "Empty")
  71.   ) ;End if
  72. ) ;end while
  73.  
  74. (setvar "osmode" smd)
  75. (setvar "attreq" arq)
  76. (setvar "attdia" atd)
  77.  
  78. (close "eqdataf") ;CLOSES THE OPEN DATA FILE
  79.  
  80.   (setvar "cmdecho" 1)
  81. ) ;end defun
  82.  
  83. ;------------------------------
  84. ;SPARSE Function (from bryan)
  85.  
  86. (defun sparse (s asep / slen ll temp cnt)
  87.   (setq temp "" slen (strlen s) cnt 0)
  88.         (< cnt slen)
  89.         (setq cnt (1+ cnt))
  90.   (if (= (substr s cnt 1) asep) ;test if character is a seperator
  91.         (setq ll(cons temp ll) ;then adds var to list
  92.         temp "")
  93.         (setq temp (strcat temp (substr s cnt 1))) ;else
  94.         ) ;end if
  95.         ) ;end while
  96.   (reverse (cons temp ll))
  97.   ) ;return list ll in order data was read
  98. ;------------------------------------
  99.  

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Update Drawings with Blocks and Attīs
« Reply #1 on: October 30, 2016, 02:29:54 PM »
You should give us a sample data file for testing.
Looking at the routine I would read the data file into memory, close it and then error check it and THEN insert the blocks.
I've reached the age where the happy hour is a nap. (°ŋ°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Soui21

  • Guest
Re: Update Drawings with Blocks and Attīs
« Reply #2 on: October 30, 2016, 02:43:27 PM »
Attached you find the samples

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Update Drawings with Blocks and Attīs
« Reply #3 on: October 31, 2016, 06:47:43 AM »
The error probably comes from the last line in the text file.  It is empty.  Try simply removing that line.

-David
R12 Dos - A2K

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Update Drawings with Blocks and Attīs
« Reply #4 on: October 31, 2016, 08:52:09 AM »
One error - fehler may be from this line :
(close "eqdataf") ;CLOSES THE OPEN DATA FILE

Change it to :
(close eqdatal) ;CLOSES THE OPEN DATA FILE
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Soui21

  • Guest
Re: Update Drawings with Blocks and Attīs
« Reply #5 on: November 01, 2016, 04:21:18 AM »
oops i saw i have attached the old DWG with only 1 block.

i will fix this this evening.