dexus Posted 20 hours ago Posted 20 hours ago Hello everyone, I'm trying to extract points/vertices from a 3D solid. The first way I tried was by exploding it into lines and arcs and then collecting the points. This works, but it is very slow. After that I found ACISdecode function by Kailas Dhage and used it to get some information about the 3D Solid. On a lot of 3D Solid it works and extracts the points correctly. But sometimes if I move the object, the point's inside of the ACIS data don't move. I'm trying to find where the transformation is stored so I can apply it to the exported points as well, but can't seem to find it. Code to export the points below, and an example drawing attached on which it doesn't work correctly. Hope someone can guide me in the right direction! (defun c:solid->pts ( / ent enx i rtn _acis) (defun _acis (enx / itm lin dxf str cha rtn) ; ACISdecode by Kailas Dhage (kailas@uts.com) ; Newsgroups: autodesk.autocad.customization 1999/05/10 ; Modified to work directly on entget data by dexus 2025/08/11 (while (setq dxf (assoc 1 enx)) (setq str (reverse (vl-string->list (cdr dxf))) itm nil lin nil) (while str (setq cha (car str) str (cdr str)) (cond ((= cha 95)) ((= cha 86) (setq itm (cons 73 itm))) ((= cha 32) (setq lin (cons (if itm (vl-list->string itm) "") lin) itm nil)) ((boole 6 cha 95) (setq itm (cons (boole 6 cha 95) itm))) ) ) (setq rtn (cons (cons (if itm (vl-list->string itm) "") lin) rtn) enx (cdr (member dxf enx))) ) (reverse rtn) ) (if (and (setq ent (car (entsel))) (setq enx (entget ent)) ) (foreach i (_acis enx) ; Princ result of the ACIS decode (princ "\n") (princ (vl-prin1-to-string i)) (if (and (equal (car i) "point") (> (length i) 5) (setq i (cddddr i))) (entmakex (list '(0 . "POINT") (cons 10 (list (distof (car i)) (distof (cadr i)) (distof (caddr i)) ) ) ) ) ) ) ) (princ) ) points.dwg Quote
dexus Posted 5 hours ago Author Posted 5 hours ago Below is the output I get from the routine, but I cant find where the transform is made... ("21800" "93" "2" "12" "" "" "" "" "" "" "" "" "" "") ("16" "\001utodesk" "\001uto\003\001\004" "19" "\001\023\r" "220.0.0.5400" "\016\024" "0" "" "") ("25.399999999999999" "9.9999999999999995e-007" "1e-010" "") ("asmheader" "$-1" "-1" "12" "220.0.0.5400" "#") ("body" "$-1" "-1" "$-1" "$2" "$-1" "$3" "#") ("lump" "$-1" "-1" "$-1" "$-1" "$4" "$1" "#") ("#") ("shell" "$-1" "-1" "$-1" "$-1" "$-1" "$5" "$-1" "$2" "#") ("face" "$6" "-1" "$-1" "$7" "$8" "$4" "$-1" "$9" "forward" "single" "#") ("persubent-acad\023olid\010istory-attrib" "$-1" "-1" "$-1" "$-1" "$5" "1" "1" "2" "0" "#") ("face" "$10" "-1" "$-1" "$11" "$12" "$4" "$-1" "$13" "forward" "single" "#") ("loop" "$-1" "-1" "$-1" "$-1" "$14" "$5" "#") ("plane-surface" "$-1" "-1" "$-1" "0" "100" "0" "-1" "0" "0" "0" "-1" "0" "forward\037v" "I" "I" "I" "I" "#") ("persubent-acad\023olid\010istory-attrib" "$-1" "-1" "$-1" "$-1" "$7" "1" "1" "3" "0" "#") ("face" "$15" "-1" "$-1" "$16" "$17" "$4" "$-1" "$18" "forward" "single" "#") ("loop" "$-1" "-1" "$-1" "$-1" "$19" "$7" "#") ("plane-surface" "$-1" "-1" "$-1" "100" "100" "0" "0" "1" "-0" "-1" "0" "0" "forward\037v" "I" "I" "I" "I" "#") ("coedge" "$-1" "-1" "$-1" "$20" "$21" "$22" "$23" "forward" "$8" "0" "$-1" "#") ("persubent-acad\023olid\010istory-attrib" "$-1" "-1" "$-1" "$-1" "$11" "1" "1" "4" "0" "#") ("face" "$24" "-1" "$-1" "$25" "$26" "$4" "$-1" "$27" "forward" "single" "#") ("loop" "$-1" "-1" "$-1" "$-1" "$28" "$11" "#") ("plane-surface" "$-1" "-1" "$-1" "100" "0" "0" "1" "0" "0" "0" "1" "0" "forward\037v" "I" "I" "I" "I" "#") ("coedge" "$-1" "-1" "$-1" "$29" "$30" "$31" "$32" "forward" "$12" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$33" "$14" "$34" "$35" "forward" "$8" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$14" "$33" "$29" "$36" "reversed" "$8" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$31" "$37" "$14" "$23" "reversed" "$38" "0" "$-1" "#") ("edge" "$-1" "-1" "$-1" "$39" "0" "$40" "100" "$14" "$41" "forward" "7" "unknown" "#") ("persubent-acad\023olid\010istory-attrib" "$-1" "-1" "$-1" "$-1" "$16" "1" "1" "1" "0" "#") ("face" "$42" "-1" "$-1" "$43" "$44" "$4" "$-1" "$45" "forward" "single" "#") ("loop" "$-1" "-1" "$-1" "$-1" "$46" "$16" "#") ("plane-surface" "$-1" "-1" "$-1" "0" "0" "0" "0" "-1" "0" "1" "0" "0" "forward\037v" "I" "I" "I" "I" "#") ("coedge" "$-1" "-1" "$-1" "$47" "$48" "$49" "$50" "forward" "$17" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$51" "$19" "$21" "$36" "forward" "$12" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$19" "$51" "$47" "$52" "reversed" "$12" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$49" "$22" "$19" "$32" "reversed" "$38" "0" "$-1" "#") ("edge" "$-1" "-1" "$-1" "$53" "0" "$39" "100" "$19" "$54" "forward" "7" "unknown" "#") ("coedge" "$-1" "-1" "$-1" "$21" "$20" "$55" "$56" "reversed" "$8" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$46" "$57" "$20" "$35" "reversed" "$26" "0" "$-1" "#") ("edge" "$-1" "-1" "$-1" "$40" "0" "$58" "100" "$34" "$59" "forward" "7" "unknown" "#") ("edge" "$-1" "-1" "$-1" "$39" "0" "$60" "100" "$29" "$61" "forward" "7" "unknown" "#") ("coedge" "$-1" "-1" "$-1" "$22" "$49" "$46" "$62" "reversed" "$38" "0" "$-1" "#") ("loop" "$-1" "-1" "$-1" "$-1" "$37" "$43" "#") ("vertex" "$-1" "-1" "$-1" "$32" "1" "$63" "#") ("vertex" "$-1" "-1" "$-1" "$62" "0" "$64" "#") ("straight-curve" "$-1" "-1" "$-1" "0" "100" "0" "0" "-1" "0" "\006" "0" "\006" "100" "#") ("persubent-acad\023olid\010istory-attrib" "$-1" "-1" "$-1" "$-1" "$25" "1" "1" "1000000000" "2" "#") ("face" "$65" "-1" "$-1" "$-1" "$38" "$4" "$-1" "$66" "reversed" "single" "#") ("loop" "$-1" "-1" "$-1" "$-1" "$67" "$25" "#") ("plane-surface" "$-1" "-1" "$-1" "50" "50" "100" "0" "0" "1" "1" "0" "0" "forward\037v" "I" "I" "I" "I" "#") ("coedge" "$-1" "-1" "$-1" "$68" "$34" "$37" "$62" "forward" "$26" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$69" "$28" "$30" "$52" "forward" "$17" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$28" "$69" "$68" "$70" "reversed" "$17" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$37" "$31" "$28" "$50" "reversed" "$38" "0" "$-1" "#") ("edge" "$-1" "-1" "$-1" "$71" "0" "$53" "100" "$28" "$72" "forward" "7" "unknown" "#") ("coedge" "$-1" "-1" "$-1" "$30" "$29" "$73" "$74" "reversed" "$12" "0" "$-1" "#") ("edge" "$-1" "-1" "$-1" "$53" "0" "$75" "100" "$47" "$76" "forward" "7" "unknown" "#") ("vertex" "$-1" "-1" "$-1" "$50" "1" "$77" "#") ("straight-curve" "$-1" "-1" "$-1" "100" "100" "0" "-1" "0" "0" "\006" "0" "\006" "100" "#") ("coedge" "$-1" "-1" "$-1" "$67" "$73" "$33" "$56" "forward" "$44" "0" "$-1" "#") ("edge" "$-1" "-1" "$-1" "$60" "0" "$58" "100" "$33" "$78" "forward" "7" "unknown" "#") ("coedge" "$-1" "-1" "$-1" "$34" "$68" "$67" "$79" "reversed" "$26" "0" "$-1" "#") ("vertex" "$-1" "-1" "$-1" "$35" "1" "$80" "#") ("straight-curve" "$-1" "-1" "$-1" "0" "0" "0" "0" "0" "1" "I" "I" "#") ("vertex" "$-1" "-1" "$-1" "$36" "1" "$81" "#") ("straight-curve" "$-1" "-1" "$-1" "0" "100" "0" "0" "0" "1" "I" "I" "#") ("edge" "$-1" "-1" "$-1" "$40" "0" "$71" "100" "$46" "$82" "forward" "7" "unknown" "#") ("point" "$-1" "-1" "$-1" "0" "100" "0" "#") ("point" "$-1" "-1" "$-1" "0" "0" "0" "#") ("persubent-acad\023olid\010istory-attrib" "$-1" "-1" "$-1" "$-1" "$43" "1" "1" "1000000000" "1" "#") ("plane-surface" "$-1" "-1" "$-1" "50" "50" "0" "0" "0" "1" "1" "0" "0" "forward\037v" "I" "I" "I" "I" "#") ("coedge" "$-1" "-1" "$-1" "$83" "$55" "$57" "$79" "forward" "$44" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$57" "$46" "$48" "$70" "forward" "$26" "0" "$-1" "#") ("coedge" "$-1" "-1" "$-1" "$48" "$47" "$83" "$84" "reversed" "$17" "0" "$-1" "#") ("edge" "$-1" "-1" "$-1" "$71" "0" "$85" "100" "$68" "$86" "forward" "7" "unknown" "#") ("vertex" "$-1" "-1" "$-1" "$62" "1" "$87" "#") ("straight-curve" "$-1" "-1" "$-1" "100" "0" "0" "0" "1" "0" "\006" "0" "\006" "100" "#") ("coedge" "$-1" "-1" "$-1" "$55" "$83" "$51" "$74" "forward" "$44" "0" "$-1" "#") ("edge" "$-1" "-1" "$-1" "$75" "0" "$60" "100" "$51" "$88" "forward" "7" "unknown" "#") ("vertex" "$-1" "-1" "$-1" "$52" "1" "$89" "#") ("straight-curve" "$-1" "-1" "$-1" "100" "100" "0" "0" "0" "1" "I" "I" "#") ("point" "$-1" "-1" "$-1" "100" "100" "0" "#") ("straight-curve" "$-1" "-1" "$-1" "0" "100" "100" "0" "-1" "0" "I" "I" "#") ("edge" "$-1" "-1" "$-1" "$58" "0" "$85" "100" "$57" "$90" "forward" "7" "unknown" "#") ("point" "$-1" "-1" "$-1" "0" "0" "100" "#") ("point" "$-1" "-1" "$-1" "0" "100" "100" "#") ("straight-curve" "$-1" "-1" "$-1" "0" "0" "0" "1" "0" "0" "\006" "0" "\006" "100" "#") ("coedge" "$-1" "-1" "$-1" "$73" "$67" "$69" "$84" "forward" "$44" "0" "$-1" "#") ("edge" "$-1" "-1" "$-1" "$85" "0" "$75" "100" "$69" "$91" "forward" "7" "unknown" "#") ("vertex" "$-1" "-1" "$-1" "$70" "1" "$92" "#") ("straight-curve" "$-1" "-1" "$-1" "100" "0" "0" "0" "0" "1" "I" "I" "#") ("point" "$-1" "-1" "$-1" "100" "0" "0" "#") ("straight-curve" "$-1" "-1" "$-1" "100" "100" "100" "-1" "0" "0" "I" "I" "#") ("point" "$-1" "-1" "$-1" "100" "100" "100" "#") ("straight-curve" "$-1" "-1" "$-1" "0" "0" "100" "1" "0" "0" "I" "I" "#") ("straight-curve" "$-1" "-1" "$-1" "100" "0" "100" "0" "1" "0" "I" "I" "#") ("point" "$-1" "-1" "$-1" "100" "0" "100" "#") Quote
hosneyalaa Posted 4 hours ago Posted 4 hours ago TRY @dexus https://www.theswamp.org/index.php?topic=59838.0 try this ;------------------------------------------------------------------------------- ; EVS extract_vertices_from_solid ; EVSD extract_vertices_from_solid and dwaw point ; EVSE extract_vertices_from_solid and erase solid ; EVSED extract_vertices_from_solid and erase solid and draw points ;------------------------------------------------------------------------------ ; Written by Giovanni Anzani, ; University of florence ; Departement DIDA of architecture ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- (defun c:EVS () (extract_vertices_from_solid (car (entsel "\nSelect solid:")) nil nil)) (defun c:EVSD () (extract_vertices_from_solid (car (entsel "\nSelect solid:")) nil T)) (defun c:EVSE () (extract_vertices_from_solid (car (entsel "\nSelect solid:")) T nil)) (defun c:EVSED () (extract_vertices_from_solid (car (entsel "\nSelect solid:")) T T)) ;------------------------------------------------------------------------------------------------- (defun CMD-0 () (setq cm_old (getvar "cmdecho" )) (setvar "cmdecho" 0 )) (defun OSM-0 () (setq os_old (getvar "osmode" )) (setvar "osmode" 0 )) (defun BLI-0 () (setq bl_old (getvar "blipmode" )) (setvar "blipmode" 0 )) ;-------------------------------------------------------------------------------------------------- (defun CMD-P () (setvar "cmdecho" cm_old )) (defun OSM-P () (setvar "osmode" os_old )) (defun BLI-P () (setvar "blipmode" bl_old )) ;-------------------------------------------------------------------------------------------------- (defun VAR-0 () (CMD-0) (OSM-0) (BLI-0)) (defun VAR-P () (CMD-P) (OSM-P) (BLI-P) (command "_redraw") (princ)) ;-------------------------------------------------------------------------------------------------- (defun Draw_lPu (lPu / Pu) (VAR-0) (foreach Pu lPu (vl-cmdf "._point" Pu)) (VAR-P)) ;-------------------------------------------------------------------------------------------------- (defun remove_duplicates_from_list (l_raw / element l_clean) (while l_raw (setq element (car l_raw) l_clean (cons element l_clean) l_raw (vl-remove element l_raw))) (reverse l_clean)) ;-------------------------------------------------------------------------------------------------- (defun entnext_from_ent_to_end (ent0 / ent1 lent) (while (setq ent1 (entnext ent0)) (setq lent (cons ent1 lent) ent0 ent1) lent)) ;-------------------------------------------------------------------------------------------------- ; if you want, you can eliminate duplicates (defun extract_edges_from_solid (ent0 erase_solid / Pu0 ent1 lis_ent) (setq Pu0 '(0.0 0.0 0.0)) (command-s "._copy" ent0 "" Pu0 Pu0) (setq ent1 (entlast)) (command-s "._copy" ent1 "" Pu0 Pu0) (repeat 2 (foreach ent (entnext_from_ent_to_end ent1) (command-s "._explode" ent ""))) (setq lis_ent (entnext_from_ent_to_end ent1)) (if erase_solid (command-s "._erase" ent0 ent1 "") (command-s "._erase" ent1 "")) lis_ent) ;--------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------- (defun extract_vertices_from_solid (ent0 erase_solid draw_points / eent Pu1 Pu2 lis_Pu) (foreach ent (extract_edges_from_solid ent0 erase_solid) (if ent (progn (setq eent (vlax-ename->vla-object ent) Pu1 (vlax-curve-getStartPoint eent) eent_open (not (vlax-curve-isClosed eent)) Pu2 (if eent_open (vlax-curve-getEndPoint eent))) (command-s "._erase" ent ""))) (if Pu1 (setq lis_Pu (if (member Pu1 lis_Pu) lis_Pu (cons Pu1 lis_Pu)))) (if Pu2 (setq lis_Pu (if (member Pu2 lis_Pu) lis_Pu (cons Pu2 lis_Pu))))) (setq lis_Pu (remove_duplicates_from_list lis_Pu)) (if draw_points (Draw_lPu lis_Pu)) lis_Pu) ;----------------------------------------------------------------------------------------------- ; EOF ;----- 1 Quote
dexus Posted 2 hours ago Author Posted 2 hours ago Thanks! Code works fine, but I do prefer not to explode the solids. And the EVSD function has a problem with points snapping to the wrong position, adding "_none" to copy command might fix that. The link you posted mentioned the xedges command, which works quite well. Still prefer to do it without drawing or exploding anything, but this code works good enough for now: (defun solid->pts (ent / itm rtn) (setq itm (entlast)) (command "_xedges" ent) (while (> (getvar "cmdactive") 0) (command "") ) (while (setq itm (entnext itm)) (setq rtn (vl-list* (vlax-curve-getStartPoint itm) (vlax-curve-getEndPoint itm) rtn ) ) (if (entget itm) (entdel itm) ) ) (removeDuplicates (vl-remove nil rtn)) ) ; RemoveDuplicates - MP ; https://www.theswamp.org/index.php?topic=4144.msg49515#msg49515 (defun RemoveDuplicates (lst / index) (vl-remove-if 'RemoveDuplicatesSub lst) ) (defun RemoveDuplicatesSub (x) (cond ((vl-position x index)) ((null (setq index (cons x index)))) ) ) If anyone knows how to do it with the acis data, I would still love to hear it. Quote
Danielm103 Posted 1 hour ago Posted 1 hour ago With ARX, you can use Brep or AssocPersSubentIdPE, the later is a bit simpler to use. AssocPersSubentIdPE will get you the faces, edges, and vertices of the solid. In the case of a cuboid, simply get all the edges and map them to a vertex In this example each vertex should be mapped to three edges. You could then build a transformation matrix so you can accurately compute the dimensions. It starts to get a lot harder with more complex shapes. There’s a few threads at the swamp discussing ideas how to work with I-beams, how to find the edge the run along the length for reference import traceback from pyrx import Ap, Ax, Ge, Ed, Db, command from collections import defaultdict @command def doit(): ps, id, pnt = Ed.Editor.entSel("\nPick it: \n", Db.Solid3d.desc()) solid = Db.Solid3d(id) pe = Db.AssocPersSubentIdPE(solid.queryX(Db.AssocPersSubentIdPE.desc())) edge_map = defaultdict(list[Ge.Curve3d]) for vrt in pe.getAllSubentities(solid, Db.SubentType.kVertexSubentType): edge_map[pe.getVertexSubentityGeometry(solid, vrt)] for edge in pe.getAllSubentities(solid, Db.SubentType.kEdgeSubentType): crv = pe.getEdgeSubentityGeometry(solid, edge) edge_map[crv.getStartPoint()].append(crv) edge_map[crv.getEndPoint()].append(crv) for k, v in edge_map.items(): for _crv in v: Ed.Core.grDraw(_crv.getStartPoint(), _crv.getEndPoint(), 1, 0) return Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.