View Full Version : m2s lisp routine
neilma
31st Mar 2004, 03:13 am
Does anyone have the lisp to convert mesh to solids available to share?
Thanks in Advance
Neil
fuccaro
31st Mar 2004, 06:38 am
Did you search in this Forum for older posts? I am sure I posted the link before...
Well, not big deal: here is the link: http://www.accustudio.com/marketplace/freeware.htm
neilma
31st Mar 2004, 09:28 pm
Hi Fuccaro,
Thank you for the link, I did do an extensive search through the forum and saw that you had posted this link previously. Unfortunatley the link no longer works (for me anyway) the page returns "The page cannot be found
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable."
I also did a Google search of "m2s.lsp" and found an Italian version of the lisp, but cannot read the command line prompts!
Still looking!, Neil
robfowler
31st Mar 2004, 10:28 pm
Just tried Fuccaro's link and it worked fine for me.
Try again.
Rob.
neilma
31st Mar 2004, 10:39 pm
Hi robfowler,
fuccaro's link "http://www.accustudio.com/marketplace/freeware.htm" does work :lol: , the link to the actual lisp file does not :cry: . Try the following;
http://www.accustudio.com/marketplace/free/m2s.zip
Am I wrong :? ?
Neil
Flores
1st Apr 2004, 02:25 am
Here is the code:
;; M2S (Mesh-to-Solid)
;; Creates an ACIS solid from an open 3d polygon mesh.
;;
;; Take 2 - Updated 7/7/1998
;; - Works with REVSURF'd meshes that touch or cross axis of revolution.
;; - Works even if solid being constructed is not fully visible on screen.
;; - Works with all open meshes created with REVSURF, RULESURF,
;; EDGESURF, TABSURF, AI_MESH, and 3DMESH. Most of the stock 3D
;; surfaces will work if you use DDMODIFY to open them in the M
;; and N directions.
;; - Does not work with polyface entities.
;;
;; (c) Copyright 1998 Bill Gilliss.
;; All rights reserved... such as they are.
;;
;; bill.gilliss@aya.yale.edu gilliss@iglou.com
;;
;; I wrote this to create sculptable ACIS terrain models
;; for architectural site renderings. It could also be used
;; to create thin shells from meshes, by subtracting a moved
;; copy of the solid from the original solid. Let me know of
;; other uses you find for it, or problems you encounter.
;;
;; The solid is created by projecting each mesh facet "down"
;; the current z-axis to a plane a user-specified distance below
;; the lowest vertex. To assure that all parts of the mesh are
;; generated as solids, this distance can not be zero, but the
;; solid can be SLICEd later if need be.
;;
;; The solid will match the displayed mesh: if the mesh has
;; been smoothed and SPLFRAME is set to 0, the solid will be
;; smoothed. Otherwise, it will not be. The mesh itself is not
;; changed at all.
;;
(defun c:m2s (/ ent ename entlst M N MN SN SM ST smooth oldecho vtx d1
low vtxcnt vtxmax bot bottom p1 p2 p3 p4 c1 c2 c3 c4
b1 b2 b3 b4 soldepth ssall ssrow)
(setq oldecho (getvar "cmdecho"))
(setq oldsnap (getvar "osmode"))
(setq oldblip (getvar "blipmode"))
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(setvar "blipmode" 0)
(command "undo" "begin")
;;select the mesh
(setq ent (entsel "Select a polygon mesh to solidify: "))
(setq ename (car ent))
(setq entlst (entget ename))
(if (not (= (cdr (assoc 0 entlst)) "POLYLINE"))
(progn
(alert "That is not a polygon mesh.")
(exit)
(princ)
);progn
);endif
(if
(not
(or
(= (cdr (assoc 70 entlst)) 16) ;open 3d polygon mesh
(= (cdr (assoc 70 entlst)) 20) ;open mesh w/ spline-fit vertices
);or
);not
(progn
(alert "That is not an *open* polygon mesh.")
(exit)
(princ)
);progn
);endif
;; decide whether to use smoothed or unsmoothed vertices
(setq M (cdr (assoc 71 entlst))) ;M vertices
(setq N (cdr (assoc 72 entlst))) ;N vertices
(setq SM (cdr (assoc 73 entlst))) ;smoothed M vertices
(setq SN (cdr (assoc 74 entlst))) ;smoothed N vertices
(setq ST (cdr (assoc 75 entlst))) ;surface type
(if
(or
(= (getvar "splframe") 1) ;use MxN vertices when splframe = 1
(= ST 0) ;or mesh has not been smoothed
)
(setq smooth 0
MN (* M N))
(setq smooth 1 ;use SMxSN vertices when mesh is smoothed
MN (* SM SN) ;and SPLFRAME = 0
M SM
N SN)
);if
;; determine lowest vertex
(grtext -2 "Checking out the mesh...")
(setq vtx ename)
(setq vtx (entnext vtx))
(setq d1 (entget vtx))
(setq bottom (caddr (trans (cdr (assoc 10 d1)) 0 1)))
(repeat (1- MN) ;compare with each vertex's z coord
(setq vtx (entnext vtx))
(setq d1 (entget vtx))
(setq low (caddr (trans (cdr (assoc 10 d1)) 0 1)))
(setq bottom (min bottom low))
);repeat
;; get desired thickness of solid
(setq soldepth 0)
(while
(zerop soldepth)
(progn
(setq soldepth
(getdist "\nEnter desired thickness of solid below lowest vertex <1>: "))
(if (not soldepth) (setq soldepth 1.0))
(if (zerop soldepth)
(princ "\nThickness can be small, but not zero. (Slice it later, if need be.)"))
);progn
);while
(setq bot (- bottom (abs soldepth)))
(setq p1 ename)
(if (= smooth 1)
(setq p1 (entnext p1))) ;skip 1st vtx of smoothed mesh - not true vtx
(setq ssrow (ssadd)) ;initialize set of extruded segments to be unioned as a row
(setq ssall (ssadd)) ;initialize set of rows to be unioned into the whole
(grtext -2 "Creating row...")
(setq vtxmax (- MN N))
(setq vtxcnt 1)
;;create row of solid segments
(while (< vtxcnt vtxmax)
(if (= 0 (rem vtxcnt N)) ;at end of each row...
(progn
(setq rowmsg (strcat "Unioning row "
(itoa (/ vtxcnt N)) " of "
(itoa (1- M)) "... "))
(grtext -2 rowmsg)
(command "union" ssrow "")
(setq row (entlast))
(ssadd row ssall)
(setq ssrow (ssadd))
(setq p1 (entnext p1) ;skip to the next vertex
vtxcnt (1+ vtxcnt))
);progn
);if
(grtext -2 "Creating row...")
(setq p1 (entnext p1) ;first vertex of mesh square
p2 (entnext p1) ;second vertex
p3 p2)
(repeat (1- n) (setq p3 (entnext p3))) ;walk along to 3rd (p1 + N) vertex
(setq p4 (entnext p3)) ;4th vertex of mesh square
(setq c1 (trans (cdr (assoc 10 (entget p1))) 0 1) ;top coordinates
c2 (trans (cdr (assoc 10 (entget p2))) 0 1)
c3 (trans (cdr (assoc 10 (entget p3))) 0 1)
c4 (trans (cdr (assoc 10 (entget p4))) 0 1)
b1 (list (car c1) (cadr c1) bot) ;bottom coordinates
b2 (list (car c2) (cadr c2) bot)
b3 (list (car c3) (cadr c3) bot)
b4 (list (car c4) (cadr c4) bot))
(LOFT c1 c2 c3 b1 b2 b3)
(LOFT c2 c3 c4 b2 b3 b4)
(setq vtxcnt (1+ vtxcnt))
);while
(grtext -2 "Unioning last row...")
(command "union" ssrow "")
(setq row (entlast))
(ssadd row ssall)
(if (> M 2) ;bypass final union for N x 1 meshes (i.e., RULESURF)
(progn
(grtext -2 "Unioning all rows...")
(command "union" ssall "")
);progn
);if
;;cleanup
(command "undo" "end")
(setvar "cmdecho" oldecho)
(setvar "osmode" oldsnap)
(setvar "blipmode" oldblip)
(setq ssall nil ssrow nil)
(princ)
);defun
;;============== SUBROUTINES ====================
;(defun *error* (msg)
; (command)
; (command "undo" "end")
; (setvar "cmdecho" oldecho)
; (setvar "osmode" oldsnap)
; (setvar "blipmode" oldblip)
; (princ (strcat "\nError: " msg))
; );defun
(defun LOFT (r1 r2 r3 s1 s2 s3 / e1 extr highest)
(command "area" s1 s2 s3 "")
(if (not (equal (getvar "area") 0.0 0.00000001))
(progn
(command "pline" s1 s2 s3 "c")
(setq highest (max (caddr r1) (caddr r2) (caddr r3)))
(setq extr (- highest bot))
(command "extrude" (entlast) "" extr 0.0)
(command "slice" (entlast) "" "3points" r1 r2 r3 s1)
(setq e1 (entlast))
(ssadd e1 ssrow)
);progn
);if
);defun
(princ "M2S loaded.")
Flores
neilma
1st Apr 2004, 02:43 am
Flores,
Thank You,
Neil
hyposmurf
7th May 2004, 12:41 pm
Is there a way to do the revers?Say from solid to mesh?
David Bethel
7th May 2004, 01:10 pm
You can do a 3DSOUT and then 3DSIN. Beware, 3DS stuff in ACAD makes a lot of faces. They 3 sided faces only, never 4 sided. -David
hyposmurf
7th May 2004, 01:16 pm
I'll try it out later thanks.
fuccaro
7th May 2004, 02:10 pm
How about EXPLODE the solid and delete the unwanted surfaces?
Paladin69
11th Jul 2005, 08:13 pm
'That is not an *open* polygon mesh' :(
That is the error message I get. I really need this to work for me but it looks like this doesn't with "polyface entities", and that's exactly what it says I have when ddmodify is run, and I have a lot of objects like that too.
This is an old tool. (1998 it says)
Is there a newer LSP or a different LSP tool?, or does anyone know how I can convert my stuff to an "open" polygon mesh so I can use this?
I'm really stuck and need some help.
sychern
10th Aug 2005, 06:46 am
I would like to know how to use it?
I saw "M2S loaded" on command like but don't know what to do next.
erona
10th Aug 2005, 08:20 am
Type M2S then select your mesh.
kellenhaskell
22nd Oct 2008, 03:27 pm
I have autocad 2007 and 3DSOUT comes out as "Unknown Command"???
lewysr
23rd Sep 2010, 01:34 pm
Might be a stupid question, but how would i go about executing the M2S.lsp?
Thanks for any help
ReMark
23rd Sep 2010, 01:44 pm
First you have to load it. You can do this with the APPLOAD command.
Then all you do is type M2S and select your mesh.
lewysr
23rd Sep 2010, 02:46 pm
Thanks ReMark.
I have loaded it and when i type M2S it tells me unknow command.
To create the lisp, i copied the text on page one, opened lisp editor, pasted, save as M2S.lisp then loaded that.
Not having much luck though :(
fuccaro
23rd Sep 2010, 08:35 pm
From the latest forum software upgrade we have some character code problems. The Lisp routine posted by our old friend Flores is affected too, I will ask David to take care of the code.
lewysr, you don't have to use the lisp editor -unless if you try to modify the code. Paste in Notepad, save the file with LSP extension and drag the file icon in the drawing area to load it.
girrrrrrr2
30th Sep 2010, 04:14 pm
;; M2S (Mesh-to-Solid)
;; Creates an ACIS solid from an open 3d polygon mesh.
;;
;; Take 2 - Updated 7/7/1998
;; - Works with REVSURF'd meshes that touch or cross axis of revolution.
;; - Works even if solid being constructed is not fully visible on screen.
;; - Works with all open meshes created with REVSURF, RULESURF,
;; EDGESURF, TABSURF, AI_MESH, and 3DMESH. Most of the stock 3D
;; surfaces will work if you use DDMODIFY to open them in the M
;; and N directions.
;; - Does not work with polyface entities.
;;
;; (c) Copyright 1998 Bill Gilliss.
;; All rights reserved... such as they are.
;;
;; bill.gilliss@aya.yale.edu gilliss@iglou.com
;;
;; I wrote this to create sculptable ACIS terrain models
;; for architectural site renderings. It could also be used
;; to create thin shells from meshes, by subtracting a moved
;; copy of the solid from the original solid. Let me know of
;; other uses you find for it, or problems you encounter.
;;
;; The solid is created by projecting each mesh facet "down"
;; the current z-axis to a plane a user-specified distance below
;; the lowest vertex. To assure that all parts of the mesh are
;; generated as solids, this distance can not be zero, but the
;; solid can be SLICEd later if need be.
;;
;; The solid will match the displayed mesh: if the mesh has
;; been smoothed and SPLFRAME is set to 0, the solid will be
;; smoothed. Otherwise, it will not be. The mesh itself is not
;; changed at all.
;;
(defun c:m2s (/ ent ename entlst M N MN SN SM ST smooth oldecho vtx d1
low vtxcnt vtxmax bot bottom p1 p2 p3 p4 c1 c2 c3 c4
b1 b2 b3 b4 soldepth ssall ssrow)
(setq oldecho (getvar "cmdecho"))
(setq oldsnap (getvar "osmode"))
(setq oldblip (getvar "blipmode"))
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(setvar "blipmode" 0)
(command "undo" "begin")
;;select the mesh
(setq ent (entsel "Select a polygon mesh to solidify: "))
(setq ename (car ent))
(setq entlst (entget ename))
(if (not (= (cdr (assoc 0 entlst)) "POLYLINE"))
(progn
(alert "That is not a polygon mesh.")
(exit)
(princ)
);progn
);endif
(if
(not
(or
(= (cdr (assoc 70 entlst)) 16) ;open 3d polygon mesh
(= (cdr (assoc 70 entlst)) 20) ;open mesh w/ spline-fit vertices
);or
);not
(progn
(alert "That is not an *open* polygon mesh.")
(exit)
(princ)
);progn
);endif
;; decide whether to use smoothed or unsmoothed vertices
(setq M (cdr (assoc 71 entlst))) ;M vertices
(setq N (cdr (assoc 72 entlst))) ;N vertices
(setq SM (cdr (assoc 73 entlst))) ;smoothed M vertices
(setq SN (cdr (assoc 74 entlst))) ;smoothed N vertices
(setq ST (cdr (assoc 75 entlst))) ;surface type
(if
(or
(= (getvar "splframe") 1) ;use MxN vertices when splframe = 1
(= ST 0) ;or mesh has not been smoothed
)
(setq smooth 0
MN (* M N))
(setq smooth 1 ;use SMxSN vertices when mesh is smoothed
MN (* SM SN) ;and SPLFRAME = 0
M SM
N SN)
);if
;; determine lowest vertex
(grtext -2 "Checking out the mesh...")
(setq vtx ename)
(setq vtx (entnext vtx))
(setq d1 (entget vtx))
(setq bottom (caddr (trans (cdr (assoc 10 d1)) 0 1)))
(repeat (1- MN) ;compare with each vertex's z coord
(setq vtx (entnext vtx))
(setq d1 (entget vtx))
(setq low (caddr (trans (cdr (assoc 10 d1)) 0 1)))
(setq bottom (min bottom low))
);repeat
;; get desired thickness of solid
(setq soldepth 0)
(while
(zerop soldepth)
(progn
(setq soldepth
(getdist "\nEnter desired thickness of solid below lowest vertex <1>: "))
(if (not soldepth) (setq soldepth 1.0))
(if (zerop soldepth)
(princ "\nThickness can be small, but not zero. (Slice it later, if need be.)"))
);progn
);while
(setq bot (- bottom (abs soldepth)))
(setq p1 ename)
(if (= smooth 1)
(setq p1 (entnext p1))) ;skip 1st vtx of smoothed mesh - not true vtx
(setq ssrow (ssadd)) ;initialize set of extruded segments to be unioned as a row
(setq ssall (ssadd)) ;initialize set of rows to be unioned into the whole
(grtext -2 "Creating row...")
(setq vtxmax (- MN N))
(setq vtxcnt 1)
;;create row of solid segments
(while (< vtxcnt vtxmax)
(if (= 0 (rem vtxcnt N)) ;at end of each row...
(progn
(setq rowmsg (strcat "Unioning row "
(itoa (/ vtxcnt N)) " of "
(itoa (1- M)) "... "))
(grtext -2 rowmsg)
(command "union" ssrow "")
(setq row (entlast))
(ssadd row ssall)
(setq ssrow (ssadd))
(setq p1 (entnext p1) ;skip to the next vertex
vtxcnt (1+ vtxcnt))
);progn
);if
(grtext -2 "Creating row...")
(setq p1 (entnext p1) ;first vertex of mesh square
p2 (entnext p1) ;second vertex
p3 p2)
(repeat (1- n) (setq p3 (entnext p3))) ;walk along to 3rd (p1 + N) vertex
(setq p4 (entnext p3)) ;4th vertex of mesh square
(setq c1 (trans (cdr (assoc 10 (entget p1))) 0 1) ;top coordinates
c2 (trans (cdr (assoc 10 (entget p2))) 0 1)
c3 (trans (cdr (assoc 10 (entget p3))) 0 1)
c4 (trans (cdr (assoc 10 (entget p4))) 0 1)
b1 (list (car c1) (cadr c1) bot) ;bottom coordinates
b2 (list (car c2) (cadr c2) bot)
b3 (list (car c3) (cadr c3) bot)
b4 (list (car c4) (cadr c4) bot))
(LOFT c1 c2 c3 b1 b2 b3)
(LOFT c2 c3 c4 b2 b3 b4)
(setq vtxcnt (1+ vtxcnt))
);while
(grtext -2 "Unioning last row...")
(command "union" ssrow "")
(setq row (entlast))
(ssadd row ssall)
(if (> M 2) ;bypass final union for N x 1 meshes (i.e., RULESURF)
(progn
(grtext -2 "Unioning all rows...")
(command "union" ssall "")
);progn
);if
;;cleanup
(command "undo" "end")
(setvar "cmdecho" oldecho)
(setvar "osmode" oldsnap)
(setvar "blipmode" oldblip)
(setq ssall nil ssrow nil)
(princ)
);defun
;;============== SUBROUTINES ====================
;(defun *error* (msg)
; (command)
; (command "undo" "end")
; (setvar "cmdecho" oldecho)
; (setvar "osmode" oldsnap)
; (setvar "blipmode" oldblip)
; (princ (strcat "\nError: " msg))
; );defun
(defun LOFT (r1 r2 r3 s1 s2 s3 / e1 extr highest)
(command "area" s1 s2 s3 "")
(if (not (equal (getvar "area") 0.0 0.00000001))
(progn
(command "pline" s1 s2 s3 "c")
(setq highest (max (caddr r1) (caddr r2) (caddr r3)))
(setq extr (- highest bot))
(command "extrude" (entlast) "" extr 0.0)
(command "slice" (entlast) "" "3points" r1 r2 r3 s1)
(setq e1 (entlast))
(ssadd e1 ssrow)
);progn
);if
);defun
(princ "M2S loaded.")
I found that somewhere, but when I ran it on what should have been a polygon mesh it said it wasnt one... it may be broken in 2010...
But, in 2010 you can just use union.
Powered by vBulletin™ Version 4.1.2 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.