Hallo,
Voor mijn zaagplannen had ik graag in mijn rechthoeken automatisch de afmetingen gekregen (lengtexbreedte) in het midden van de rechthoek als ik deze teken.
Bestaat hier een command of lisp routine voor?
Ik heb internet even gezocht maar vrees dat ik niet de juiste benamingen gebruik in de zoekfuncties.
Ik kwam volgende tegen maar dit werkt niet bij me:
(defun c:LabelRec (/ ActDoc CurSpace Ht ss cnt Ent EntData VerPoints tmpEnt Wid Len Pt Str tmpText tmpDist1 tmpDist2)
; Label rectangles with length and width in middle of them.
(vl-load-com)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if (= (getvar "cvport") 1)
(setq CurSpace (vla-get-PaperSpace ActDoc))
(setq CurSpace (vla-get-ModelSpace ActDoc))
)
(if (and (setq Ht (getreal "\n Enter height of text: ")) (setq ss (ssget '((0 . "*POLYLINE")))))
(progn
(setq cnt 0)
(while (setq Ent (ssname ss cnt))
(setq EntData (entget Ent))
(if (= (cdr (assoc 0 EntData)) "LWPOLYLINE")
(setq VerPoints (vlax-get (vlax-ename->vla-object Ent) 'Coordinates))
(progn
(setq VerPoints nil)
(setq tmpEnt (entnext Ent))
(while (not (equal (cdr (assoc 0 (entget tmpEnt))) "SEQEND"))
(setq tmpPt (cdr (assoc 10 (entget tmpEnt))))
(setq VerPoints (append VerPoints (list (car tmpPt))))
(setq VerPoints (append VerPoints (list (cadr tmpPt))))
(setq tmpEnt (entnext tmpEnt))
)
)
)
(if (= (length VerPoints) 8)
(progn
(setq tmpDist1 (distance (list (nth 0 VerPOints) (nth 1 VerPoints)) (list (nth 2 VerPoints) (nth 3 VerPoints))))
(setq tmpDist2 (distance (list (nth 2 VerPOints) (nth 3 VerPoints)) (list (nth 4 VerPoints) (nth 5 VerPoints))))
(if (< tmpDist1 tmpDist2)
(setq Len tmpDist2 Wid tmpDist1)
(setq Len tmpDist1 Wid tmpDist2)
)
(setq Pt (list (/ (+ (nth 0 VerPoints) (nth 4 VerPoints)) 2.0) (/ (+ (nth 1 VerPoints) (nth 5 VerPoints)) 2.0) 0.0))
(setq Str (strcat (rtos Len 2 2) "x" (rtos Wid 2 2)))
(setq tmpText (vla-AddText CurSpace Str (vlax-3d-point Pt) Ht))
(vla-put-Alignment tmpText 4)
(vla-put-TextAlignmentPoint tmpText (vlax-3d-point Pt))
)
)
(setq cnt (1+ cnt))
)
Bedankt
Cad_User86
Wij zijn hier afgestapt om zaagplannen in AutoCAD te maken.
We gebruiken hiervoor het gratis:
http://www.maxcutsoftware.com
Die maakt naast optimalisaties ook zaagplannen waar je de naam van je onderdeel kan opzetten en ook de zaagmaten. Is dat iets voor jou?
Cad_user86, met welke (versie van) AutoCAD werkt u?
Versie 2014
ja, volledige versie
@Cad_User86:
De code in de OP is niet compleet. Wellicht een copy-paste fout?
En: Gebruik a.u.b. CODE-tags.
Dag Roy,
Ik ken zelf niets van LISP, gewoon van internet gekopieerd zoals het hier staat (site van autodesk)
Wat is "OP"? en wat zijn CODE-tags?
Bedankt! :vreegoe:
Citaat van: Cad_user86 op wo 19 10 2016, 15:22:07
Dag Roy,
Ik ken zelf niets van LISP, gewoon van internet gekopieerd zoals het hier staat (site van autodesk)
Wat is "OP"? en wat zijn CODE-tags?
Bedankt! :vreegoe:
Zie afbeelding...
Citaat van: Cad_user86 op wo 19 10 2016, 15:22:07Wat is "OP"?
OpeningsPost?
en deze tekst staat tussen code-tags
Als je bij de code in de OP op het einde 3 sluitende haken toevoegt, werkt het. Ziehier de volledige code:
(defun c:LabelRec (/ ActDoc CurSpace Ht ss cnt Ent EntData VerPoints tmpEnt Wid Len Pt Str tmpPt tmpText tmpDist1 tmpDist2)
; Label rectangles with length and width in middle of them.
(vl-load-com)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if (= (getvar "cvport") 1)
(setq CurSpace (vla-get-PaperSpace ActDoc))
(setq CurSpace (vla-get-ModelSpace ActDoc))
)
(if (and (setq Ht (getreal "\n Enter height of text: ")) (setq ss (ssget '((0 . "*POLYLINE")))))
(progn
(setq cnt 0)
(while (setq Ent (ssname ss cnt))
(setq EntData (entget Ent))
(if (= (cdr (assoc 0 EntData)) "LWPOLYLINE")
(setq VerPoints (vlax-get (vlax-ename->vla-object Ent) 'Coordinates))
(progn
(setq VerPoints nil)
(setq tmpEnt (entnext Ent))
(while (not (equal (cdr (assoc 0 (entget tmpEnt))) "SEQEND"))
(setq tmpPt (cdr (assoc 10 (entget tmpEnt))))
(setq VerPoints (append VerPoints (list (car tmpPt))))
(setq VerPoints (append VerPoints (list (cadr tmpPt))))
(setq tmpEnt (entnext tmpEnt))
)
)
)
(if (= (length VerPoints) 8)
(progn
(setq tmpDist1 (distance (list (nth 0 VerPOints) (nth 1 VerPoints)) (list (nth 2 VerPoints) (nth 3 VerPoints))))
(setq tmpDist2 (distance (list (nth 2 VerPOints) (nth 3 VerPoints)) (list (nth 4 VerPoints) (nth 5 VerPoints))))
(if (< tmpDist1 tmpDist2)
(setq Len tmpDist2 Wid tmpDist1)
(setq Len tmpDist1 Wid tmpDist2)
)
(setq Pt (list (/ (+ (nth 0 VerPoints) (nth 4 VerPoints)) 2.0) (/ (+ (nth 1 VerPoints) (nth 5 VerPoints)) 2.0) 0.0))
(setq Str (strcat (rtos Len 2 2) "x" (rtos Wid 2 2)))
(setq tmpText (vla-AddText CurSpace Str (vlax-3d-point Pt) Ht))
(vla-put-Alignment tmpText 4)
(vla-put-TextAlignmentPoint tmpText (vlax-3d-point Pt))
)
)
(setq cnt (1+ cnt))
)
)
)
)
OP staat voor 'Original Post' of 'Original Poster'.
Het werkt inderdaad....... helaas nog niet meteen wat ik zoek :-)
Het uiteindelijke resultaat is hoe ik het graag zou hebben, maar ik zou willen dat, wanneer je een rechthoek tekent, dat de tekst dan automatisch in het midden komt te staan.
Nu moet je eerst de rechthoek tekenen, vervolgens de lisp activeren, hoogt tekst ingeven en vervolgens de rechthoek selecteren. Dit alles had ik graag in één beweging gedaan...
Iemand een voorstel?
Bedankt alvast!!! :vreegoe: :vreegoe: :vreegoe: :mrgreen:
Dan zal je bovenstaande LISP code dienen uit te breiden met het RECTANG commando.
Zou je dit ook met een dynamisch block kunnen doen? Voorbeeld in de bijlage.
Reimer
Citaat van: Cad_user86 op do 20 10 2016, 08:08:52Nu moet je eerst de rechthoek tekenen, vervolgens de lisp activeren, hoogt tekst ingeven en vervolgens de rechthoek selecteren. Dit alles had ik graag in één beweging gedaan...
Je kan ook alle rechthoeken op normale wijze tekenen en de bemating op 't einde in één keer toevoegen aan alle of enkele geselecteerde rechthoeken.
Goedenavond Gery,
Kun jij (of iemand anders) het voor elkaar krijgen dat deze lisp routine de huidige tekststijl oppakt (inclusief hoogte) zodat ik de hoogte niet meer zelf hoef in te vullen? Voor mij is deze lisp dan perfect.
Met vriendelijke groet,
Adrianus.
(defun c:LabelRec (/ ActDoc CurSpace Ht ss cnt Ent EntData VerPoints tmpEnt Wid Len Pt Str tmpPt tmpText tmpDist1 tmpDist2)
; Label rectangles with length and width in middle of them.
(vl-load-com)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if (= (getvar "cvport") 1)
(setq CurSpace (vla-get-PaperSpace ActDoc))
(setq CurSpace (vla-get-ModelSpace ActDoc))
)
(if (and (setq Ht (getreal "\n Enter height of text: ")) (setq ss (ssget '((0 . "*POLYLINE")))))
(progn
(setq cnt 0)
(while (setq Ent (ssname ss cnt))
(setq EntData (entget Ent))
(if (= (cdr (assoc 0 EntData)) "LWPOLYLINE")
(setq VerPoints (vlax-get (vlax-ename->vla-object Ent) 'Coordinates))
(progn
(setq VerPoints nil)
(setq tmpEnt (entnext Ent))
(while (not (equal (cdr (assoc 0 (entget tmpEnt))) "SEQEND"))
(setq tmpPt (cdr (assoc 10 (entget tmpEnt))))
(setq VerPoints (append VerPoints (list (car tmpPt))))
(setq VerPoints (append VerPoints (list (cadr tmpPt))))
(setq tmpEnt (entnext tmpEnt))
)
)
)
(if (= (length VerPoints) 8)
(progn
(setq tmpDist1 (distance (list (nth 0 VerPOints) (nth 1 VerPoints)) (list (nth 2 VerPoints) (nth 3 VerPoints))))
(setq tmpDist2 (distance (list (nth 2 VerPOints) (nth 3 VerPoints)) (list (nth 4 VerPoints) (nth 5 VerPoints))))
(if (< tmpDist1 tmpDist2)
(setq Len tmpDist2 Wid tmpDist1)
(setq Len tmpDist1 Wid tmpDist2)
)
(setq Pt (list (/ (+ (nth 0 VerPoints) (nth 4 VerPoints)) 2.0) (/ (+ (nth 1 VerPoints) (nth 5 VerPoints)) 2.0) 0.0))
(setq Str (strcat (rtos Len 2 2) "x" (rtos Wid 2 2)))
(setq tmpText (vla-AddText CurSpace Str (vlax-3d-point Pt) Ht))
(vla-put-Alignment tmpText 4)
(vla-put-TextAlignmentPoint tmpText (vlax-3d-point Pt))
)
)
(setq cnt (1+ cnt))
)
)
)
)
Citaat van: Adrianus op zo 23 10 2016, 23:03:43
Kun jij (of iemand anders) het voor elkaar krijgen dat deze lisp routine de huidige tekststijl oppakt (inclusief hoogte) zodat ik de hoogte niet meer zelf hoef in te vullen? Voor mij is deze lisp dan perfect.
een 1e (snelle) poging:
(defun c:LabelRec (/ ActDoc CurSpace Ht ss cnt Ent EntData VerPoints tmpEnt Wid Len Pt Str tmpPt tmpText tmpDist1 tmpDist2)
; Label rectangles with length and width in middle of them.
(vl-load-com)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if (= (getvar "cvport") 1)
(setq CurSpace (vla-get-PaperSpace ActDoc))
(setq CurSpace (vla-get-ModelSpace ActDoc))
)
(if (and (setq Ht (getvar 'textsize)) (setq ss (ssget '((0 . "*POLYLINE")))))
(progn
(setq cnt 0)
(while (setq Ent (ssname ss cnt))
(setq EntData (entget Ent))
(if (= (cdr (assoc 0 EntData)) "LWPOLYLINE")
(setq VerPoints (vlax-get (vlax-ename->vla-object Ent) 'Coordinates))
(progn
(setq VerPoints nil)
(setq tmpEnt (entnext Ent))
(while (not (equal (cdr (assoc 0 (entget tmpEnt))) "SEQEND"))
(setq tmpPt (cdr (assoc 10 (entget tmpEnt))))
(setq VerPoints (append VerPoints (list (car tmpPt))))
(setq VerPoints (append VerPoints (list (cadr tmpPt))))
(setq tmpEnt (entnext tmpEnt))
)
)
)
(if (= (length VerPoints) 8)
(progn
(setq tmpDist1 (distance (list (nth 0 VerPOints) (nth 1 VerPoints)) (list (nth 2 VerPoints) (nth 3 VerPoints))))
(setq tmpDist2 (distance (list (nth 2 VerPOints) (nth 3 VerPoints)) (list (nth 4 VerPoints) (nth 5 VerPoints))))
(if (< tmpDist1 tmpDist2)
(setq Len tmpDist2 Wid tmpDist1)
(setq Len tmpDist1 Wid tmpDist2)
)
(setq Pt (list (/ (+ (nth 0 VerPoints) (nth 4 VerPoints)) 2.0) (/ (+ (nth 1 VerPoints) (nth 5 VerPoints)) 2.0) 0.0))
(setq Str (strcat (rtos Len 2 2) "x" (rtos Wid 2 2)))
(setq tmpText (vla-AddText CurSpace Str (vlax-3d-point Pt) Ht))
(vla-put-Alignment tmpText 4)
(vla-put-TextAlignmentPoint tmpText (vlax-3d-point Pt))
)
)
(setq cnt (1+ cnt))
)
)
)
)
Geweldig Gery,
Hij doet het.. :vreegoe: :vreegoe: :vreegoe:
Mijn dank is groot.
Groet,
Adrianus
Citaat van: Adrianus op ma 24 10 2016, 21:47:54Geweldig Gery,
Hij doet het.. :vreegoe: :vreegoe: :vreegoe:
Mijn dank is groot.
Graag gedaan.
Citaat van: Cad_user86 op do 20 10 2016, 08:08:52Het werkt inderdaad....... helaas nog niet meteen wat ik zoek :-)
Het uiteindelijke resultaat is hoe ik het graag zou hebben, maar ik zou willen dat, wanneer je een rechthoek tekent, dat de tekst dan automatisch in het midden komt te staan.
Een poging:
(defun c:Rect+Label (/ ActDoc CurSpace Ht ss cnt Ent EntData VerPoints tmpEnt Wid Len Pt Str tmpPt tmpText tmpDist1 tmpDist2)
; Draws a rectangle, and labels it with length and width in the middle of it.
(vl-load-com)
(command "rectang")
(while (= (logand (getvar "CmdActive") 1) 1) (command pause))
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if (= (getvar "cvport") 1)
(setq CurSpace (vla-get-PaperSpace ActDoc))
(setq CurSpace (vla-get-ModelSpace ActDoc))
)
(if (and (setq Ht (getvar 'textsize)) (setq ss (ssget "_L")))
(progn
(setq cnt 0)
(while (setq Ent (ssname ss cnt))
(setq EntData (entget Ent))
(if (= (cdr (assoc 0 EntData)) "LWPOLYLINE")
(setq VerPoints (vlax-get (vlax-ename->vla-object Ent) 'Coordinates))
(progn
(setq VerPoints nil)
(setq tmpEnt (entnext Ent))
(while (not (equal (cdr (assoc 0 (entget tmpEnt))) "SEQEND"))
(setq tmpPt (cdr (assoc 10 (entget tmpEnt))))
(setq VerPoints (append VerPoints (list (car tmpPt))))
(setq VerPoints (append VerPoints (list (cadr tmpPt))))
(setq tmpEnt (entnext tmpEnt))
)
)
)
(if (= (length VerPoints) 8)
(progn
(setq tmpDist1 (distance (list (nth 0 VerPOints) (nth 1 VerPoints)) (list (nth 2 VerPoints) (nth 3 VerPoints))))
(setq tmpDist2 (distance (list (nth 2 VerPOints) (nth 3 VerPoints)) (list (nth 4 VerPoints) (nth 5 VerPoints))))
(if (< tmpDist1 tmpDist2)
(setq Len tmpDist2 Wid tmpDist1)
(setq Len tmpDist1 Wid tmpDist2)
)
(setq Pt (list (/ (+ (nth 0 VerPoints) (nth 4 VerPoints)) 2.0) (/ (+ (nth 1 VerPoints) (nth 5 VerPoints)) 2.0) 0.0))
(setq Str (strcat (rtos Len 2 2) "x" (rtos Wid 2 2)))
(setq tmpText (vla-AddText CurSpace Str (vlax-3d-point Pt) Ht))
(vla-put-Alignment tmpText 4)
(vla-put-TextAlignmentPoint tmpText (vlax-3d-point Pt))
)
)
(setq cnt (1+ cnt))
)
)
)
)
Er zullen ongetwijfeld nog andere en betere en simpelere codes bestaan, ik heb gewoonweg ff verder gewerkt op de in dit topic aangereikte code.
Joepie,
Perfect voor wat ik ermee moet doen!
Bedankt
Citaat van: Cad_user86 op do 27 10 2016, 08:59:24Perfect voor wat ik ermee moet doen!
Bedankt
Graag gedaan.