如果你愿意的话,考虑一下你的理想结果并加以描述。如果我真的有时间去做的话,我不愿意创造出妥协的东西,然后不得不改变它。 你好
该文件将简单如下:
布局、图层、样式、X线、Y线、文字、,
22X34 LAND,INV BOLD,HAND,31,1.6,CATHY ENGEL,
22X34 LAND,INV BOLD,HAND,31,1.4,LOT 3 KEYES ROAD,
22X34 LAND,INV BOLD,HAND,31,1.2,WARREN MA,
2012年7月31日,1日,18日,手部,INV BOLD,22X34土地,
忽略文件的第一行。(标题信息)
然后,将文字“CATHY ENGEL”放置在22X34横向布局表的INV BOLD图层上,文字样式手放在x线31处,y线1.6处。这会将该文本放置在我的绘图(标题栏)的右下角。
然后对csv的其余部分执行此操作。
也许要画一个块,我可以用文字块替换文字样式,用块名替换文字值。
类似于:
22X34土地,INV BOLD,街区,31,1.6,化粪池。图纸,
因此,不要放置文本,而是放置一个名为化粪池的块。图纸将在31.1.6处插入
这些块都可以存储在同一个文件夹中以简化它。
这就是目标,只需将文本或块放置在指定的位置。
我有点精通excel,所以什么样的格式最适合csv,我可以做到。
谢谢
做记号 你好,马克,
根据你所说的你需要的,这将是我的第一次跑步。正如我所说,我不知道LISP在Intellicad中的应用是否有任何限制。
您也没有提到任何关于文本高度的内容,所以我现在使用当前textsize变量的值来实现它。文本为多行文字,默认为背景遮罩。
这是一个开始。
(defun C:ImpDes ( /
;;All Functions declared locally
ImpDes:err ImpDes:sav ImpDes:res
parsestring layouts layers
;;Saved variables for restore
ocmd olderr
;;Local Variables
data file fileline objad lay
)
(vl-load-com)
(setq objad (vla-get-activedocument (vlax-get-acad-object)))
;*******************************************************************
; Error Handling, Save and Restore
;*******************************************************************
(defun ImpDes:err (s / )
(if (/= s "Function cancelled")
(if (= s "quit / exit abort")
(princ)
(princ (strcat "\nError < " s " >"))
);if
);if
(ImpDes:res);restore environment
(princ)
)
;---------------------------------------------------------
(defun ImpDes:sav ( / )
(vla-StartUndoMark objad)
(setq ocmd (getvar "cmdecho")
olderr *error*
*error* ImpDes:err
)
(setvar "cmdecho" 0)
)
;---------------------------------------------------------
(defun ImpDes:res ( / )
(setvar "cmdecho" ocmd)
(setq *error* olderr); restore old *error* handler
(gc);garbage collection
(vla-EndUndoMark objad)
(princ)
)
;;******************************************************************
;; Local Functions
;;******************************************************************
(defun parsestring ( str / res found previous)
(setq str (vl-string-right-trim "," str)
found (vl-string-position 44 str 0)
previous -1
)
(while (and found (< found (strlen str)))
(setq res (cons (substr str (+ 2 previous) (- found previous 1)) res)
previous found
found (vl-string-position 44 str (1+ previous))
)
)
(setq res (cons (substr str (+ 2 previous)) res))
(reverse res)
)
;;******************************************************************
(defun layouts ( layout )
(if (and (not (member layout (layoutlist)))
(/= layout "Model")
)
(vla-add (vla-get-layouts objad) layout)
)
)
;;******************************************************************
(defun layers ( lay / objlay actlyr )
(if (null (tblsearch "LAYER" lay))
(vla-add (vla-get-layers objad) lay)
(progn
(setq objlay (vla-item (vla-get-layers objad) lay)
actlyr (vla-get-name (vla-get-activelayer objad))
)
(vla-put-layeron objlay :vlax-true)
(vla-put-lock objlay :vlax-false)
(if (/= lay actlyr)
(vla-put-freeze objlay :vlax-false)
)
)
);if
)
;;******************************************************************
;; Main Program Code
;;******************************************************************
(ImpDes:sav);Save variables for error handling
(if (and (setq file (getfiled "Design File To Import" "" "csv" 4))
(setq file (open file "r"))
)
(progn
(read-line file) ;ignore header info
(while (setq fileline (read-line file)) ;read whole file
(if (/= fileline "")
(setq data (append data (list (parsestring fileline)))) ;store data
)
)
(close file)
(foreach line data
(if (and (>= (length line) 6)
(apply 'and
(mapcar
(function
(lambda ( x )
(> (strlen x) 0)
)
)
line
)
)
);and
(progn
(layouts (car line))
(layers (cadr line))
(if (= (strcase (caddr line)) "BLOCK")
(if (tblsearch "BLOCK" (nth 5 line))
;LAYOUT,LAYER,BLOCK,X-CORD,Y-CORD,BLOCKNAME
(entmake (list '(0 . "INSERT")
(cons 410 (car line)) ;layout
(cons 8 (cadr line)) ;layer
(cons 2 (nth 5 line)) ;blockname
(cons 10 (list (atof (nth 3 line)) (atof (nth 4 line)) 0)) ;insert point
)
)
(princ "\nBlockname does not exist in the drawing.")
)
;LAYOUT,LAYER,TEXTSTYLE,X-CORD,Y-CORD,TEXTSTRING
(entmake (list '(0 . "MTEXT")
'(100 . "AcDbEntity")
(cons 410 (car line)) ;layout
(cons 8 (cadr line)) ;layer
'(100 . "AcDbMText")
(cons 10 (list (atof (nth 3 line)) (atof (nth 4 line)) 0)) ;insert point
(cons 40 (getvar "TEXTSIZE")) ;is textheight needed?
(cons 1 (nth 5 line)) ;textstring
(cons 7 (if (tblsearch "STYLE" (caddr line)) (caddr line) (getvar "TEXTSTYLE"))) ;textstyle
'(90 . 3)
'(63 . 256)
'(45 . 1.15)
)
)
);if
);progn
);if
);foreach
);progn
);if
(ImpDes:res);Restore variables for error handling
);defun
(Prompt "\nTHIS ROUTINE IMPORTS DESIGN DATA FROM CSV FILE (VERSION 0.0) by C.WAKEFIELD.")
(Prompt "\nType ImpDes to run.")
(princ) 香草味:
(defun c:demo (/ _delFinder collect _remd file data)
;; pBe Dec 2013 ;;
(defun _delFinder( str n / a b lst )
(while (/= "" str)
(while
(and (<= n (strlen str))
(not (wcmatch (Setq a (substr str 1 n)) "*`,*")))
(setq n (1+ n) b a))
(setq lst (cons b lst)
str (substr str (1+ n))
n 1)
)
(reverse lst)
)
;;; cwakes' idea ;;;
(defun _layoutlist(/ lyt ll)
(Setq lyt (dictsearch (namedobjdict) "ACAD_LAYOUT"))
(while (setq a (assoc 3 lyt))
(setq ll(cons (cdr a) ll)
lyt (cdr (member a lyt))))
(cdr ll)
)
(setq collect (lambda (f / a b opf)
(setq opf (open f "r"))
(read-line opf)
(while (setq a (read-line opf))
(setq b (cons (_delfinder a 1) b))
)
(close opf)
b
)
)
(setq _remd (lambda (lst / a b)
(while (setq a (car lst))
(setq b (if (not (member a b))
(cons a b)
b
)
lst (cdr lst)
)
)
b
)
)
(and
(setq
file (getfiled "Select Data file" (getvar 'dwgprefix) "csv" 16)
)
(setq data (collect file))
(foreach itm (_remd (mapcar 'car data))
(if (and (not (member itm (_layoutlist)))
(snvalid itm)
)
(command "_.layout" "_New" itm)
)
itm
)
(foreach itm (_remd (mapcar 'cadr data))
(if (and (not (tblsearch "Layer" itm))
(snvalid itm)
)
(entmake (list (cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 itm)
(cons 70 0)
)
)
itm
)
)
(foreach itm (_remd (mapcar 'caddr data))
(if (and (not (tblsearch "Style" itm))
(snvalid itm)
)
(entmake (list '(0 . "STYLE")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbTextStyleTableRecord")
(cons 2 itm)
'(70 . 0)
'(40 . 0.0125) ;<-- Text height for style
'(41 . 0.
'(50 . 0.0)
'(71 . 0)
'(3 . "ARIAL.TTF")
'(4 . "")
)
)
itm
)
)
(foreach info data
(entmakex
(list
(cons 0 "TEXT")
(cons
10
(setq p (list (distof (nth 3 info)) (distof (nth 4 info))))
)
(cons 11 p)
(cons 8 (cadr info))
(cons 7 (caddr info))
'(40 . 0.0125)
(cons 1 (nth 5 info))
'(71 . 0)
'(72 . 1)
'(73 . 2)
(cons 410 (car info))
)
)
)
)
(princ)
)
作品它应该在一个框中显示一条警报消息。 Hello,
Not being an expert I would think that IntelliCAD AutoLISP would not support ActiveX methods.
It is probably a simpler version and would support the long standing AutoLISP functions and coding methods. Nothing cutting edge.
I tried both and got error messages.
Do I need to place the csv file in a specific directory? Define anything specific in my template drawing? Any other OP actions?
Here were the error messages:
Command: impdes
null function :error#0
Command: demo
bad argument type :error#0
Thanks!!
Mark Farrell
Sturbridge, MA USA btw, pBe you signature doesn't work and cwake you don't have a link... You shouldn't have to. Both functions make use of the getfiled function which should present you with a dialogue box to browse and select the file. If you haven't seen the dialogue box, then both routines must have fallen over before they get to that.
In the case of my routine, I would guess that "null function :error#0" means as you guessed... that ActiveX methods are not supported in Intellicad.
Which means it will be better to start with pBe's routine and see why it thinks a function is being passed a "bad argument". No dialog box presented...
Can I embed statements in the code to see where it might have fallen over?
You could, and I was thinking the same. Keeping in mind that I'm suggesting sticking with pBe's routine... First I'd check to see if Intellicad has a variable "dwgprefix". Because I'm thinking that there is most likely where it might fall over. There isn't much else to evaluate before that.
Also as a method of "embedding statements", see if
(defun c:helpme ()(alert "This is debug location number 1"))
works? It should bring up an alert message in a box.
页:
1
[2]