PDA

View Full Version : Trouble with a small Lisp



todd.mackay
2004-08-25, 07:10 PM
I am working with mechanical drawings that need to have almost all the line work changed into polylines with a width of .003. These particular drawings are exploded 3D drawings in 2D (top view).
When I try to do an "mpedit" and select all, rather than telling me that objects are not polylines and do I want to convert them, I get, "582 object(s) were not parallel to the current UCS.Convert Lines and Arcs to polylines? <Yes>:." If there is a way to fix that, please tell me but I'm guessing that it's not easy. If you look at it from a right side view, you can tell that it's not on the same plan.

Now, I found that I could convert each line to a .003 PLINE. So I tried to make the long way a little faster and write a small lisp:
****************************************************************

(defun c:w003 ()
(setq lsource (entsel "Select a line:"))
(command "pedit" lsource "w" ".003" "")

(princ)
)
****************************************************************
You can tell that I'm a beginner!! The trouble that this is giving me is that it works every other time. I'll select a line and it doesn't work, then when I do a return command and go back into it, it works after I select it once more.

Also, I'm currently using Acad 14 and I don't know if that has to do with it but I know it doesn't have VLISP to help me out.

:???: Sorry so wordy,

Thanks - Todd

CADmium
2004-08-25, 07:44 PM
Test this:


(defun SET-LWEIGHT (Object LWeight / Data)
(if(and(=(type Object) 'ENAME)
(setq Data (entget Object))
)
(progn
(if (assoc 370 DATA)
(setq DATA(subst(cons 370 LWeight)(assoc 370 DATA)DATA))
(setq DATA(append DATA (list(cons 370 LWeight))))
)
(entmod DATA)
)
)
)
(defun c:W003( / Object )
(if(setq Object (car(entsel)))
(SET-LWEIGHT Object 30)
)
)

todd.mackay
2004-08-26, 12:39 PM
Sorry Dude, I'm not getting yours to work. After I select the object, it gives me:
Command:
W003
Select object: error: bad entmod list

Well, I went back to mine and noticed that I left an extra "y" out:
(command "pedit" lsource "y" "w" ".003" "")
That's working fine for now.

And don't worry, I'm sure your way better than me. Like Mr. Miyagi says in the Karate Kid, "Beginner Luck!"

CADmium
2004-08-27, 11:14 AM
Oh, you mean the width of a Polyline... sorry...

Try this:


(defun SET-POLYLWEIGHT (Object LWeight / Data)
(if(and(=(type Object) 'ENAME)
(setq Data (entget Object))
)
(cond
((=(cdr(assoc 0 Data)) "POLYLINE")
(while(and(setq Object (entnext Object))
(/=(cdr(assoc 0 (entget Object)))"SEQEND")
)
(entmod(mapcar '(lambda(X)
(if (member (car X) '(40 41))
(cons (car X) LWeight)
X
)
)
(entget Object)
)
)
)
(entmod(mapcar '(lambda(X)
(if (member (car X) '(40 41))
(cons (car X) LWeight)
X
)
)
DATA
)
)

)
((=(cdr(assoc 0 Data)) "LWPOLYLINE")
(entmod(mapcar '(lambda(X)
(if (member (car X) '(40 41 43))
(cons (car X) LWeight)
X
)
)
DATA
)
)
)
)
)
)
(defun c:W003( / Object )
(if(setq Object (car(entsel)))
(SET-PolyLWEIGHT Object 0.003)
)
)

todd.mackay
2004-08-27, 02:45 PM
All I'm getting, after I select a line, is:
Command: w003
Select object: nil

I've attached a portion of one of the drawings that I'm working on for this. The goal is to have everything converted to a polyline with a width of .003, then it will be saved as a .wmf.
As you can see, I've got some of the line work converted but some of the objects are ellipses, some are splines and some are not on the proper UCS.

I figured out that if I save it as a R12 then open it back up in R14 (that's the version I'm using), it will turn most of the ellipses and splines into plines. So I'm working on writing a lisp to take care of that part.

Thanks again - Todd

CAB2k
2004-08-28, 03:09 PM
It appears to me that what you are trying to do is:
Convert all objects, LINES, Arc's, Circles, Ellipse's, to LWpolylines
Then set all plines to width 0.003

Correct?

CAB

PS checked out Tom's routine on ACAD2000 & it worked ok on LWplines.
Some of the objects in your DWG are LINES, perhaps you selected one of those?