3dwannab Posted October 8 Posted October 8 (edited) I've recently started a new job and tidying up the detail library. The majority of the drawing is a mess and was at all different elevations. So I started by using superflatten lisp found over on theswamp but it seems that when using the below code afterward it sends the objects to the X plane which shouldn't happen. See the attached drawing. The code that I'm using is: ;; Moves all visible objects to 0.0000 on the Z plane AKA Coplanar (defun C:NONZ () (vl-cmdf ".undo" "BEGIN") ; Added Crude Error Trap AKA UNDO (setvar "cmdecho" 1) ; turn off vl-cmdf echoing (vl-cmdf "zoom" "extents") (vl-cmdf "move" "all" "" "0,0,0" "0,0,1e99") (vl-cmdf "move" "all" "" "0,0,0" "0,0,-1e99") (vl-cmdf "zoom" "previous") (setvar "cmdecho" 1) (vl-cmdf ".undo" "END") ) ; Flatten Issue.dwg Edited October 8 by 3dwannab Quote
Steven P Posted October 8 Posted October 8 Seams to work better if you move the drawing to the origin instead of (120290, -60614) Quote
3dwannab Posted October 8 Author Posted October 8 18 minutes ago, Steven P said: Seams to work better if you move the drawing to the origin instead of (120290, -60614) Can you try the attached? It doesn't work for me. test.dwg 1 Quote
eldon Posted October 8 Posted October 8 It might be that there are many objects that are not parallel the the UCS. Your lisp just moves everything to a very great height vertically. If something is not parallel to the UCS, then it moves in a direction vertical to its own UCS but not to the current UCS. I don't know how to fix this, but someone clever probably knows how. I would just redraw the leaders, dimensions and hatches. Quote
Steven P Posted October 8 Posted October 8 Just trying that, it isn't working.... but you've told me that all ready. Looks like the hatches are hatching 3d lines - If I redraw the boundaries, hatch and then NONZ the new hatch does as expected. Just thinking as a fix, select all hatches - selection set - redraw the hatch, delete the original with the hatch points all at z=0, or recreate the boundaries and new hatch from there Quote
3dwannab Posted October 8 Author Posted October 8 (edited) It would be a huge undertaking on the existing detail library in the office to redraw everything but I guess that's what I'm going to have to do. I wasn't aware that objects can still have their own UCS. I don't understand how they can appear flat in the front view. FRONT VIEW OF THE ATTACHED (not very exciting to look at) Hatch example.dwg Edited October 8 by 3dwannab 1 Quote
Steven P Posted October 8 Posted October 8 (edited) That's the first thing I looked at too - a few 3d polylines are slightly off 0 z axis (like 0.000026, something like that) LISP would do the hatches no problem I think, do as a batch process and shouldn't be too painful - lunchtime walk while the machine does it stuff. Not sure the best way to go with that yet, perhaps entmake the hatch but apply (massoc.... ) lisp to the coordinates and entmod them with the result set with z axis set to 0 (mapcar '* '(1 1 0) coord ).. think that should work? Untested code idea: - do ssget and loop through each hatch entity as HatchEnt - (setq MyHatch (entget HatchEnt)) - (setq coords (Massoc 10 MyHatch)) - (Foreach n coords - (entmod (mapcar '* '(1 1 0) n) n MyHatch) - ) ; end foreach - ent update MyHatch - delete the original hatch I tested this quickly before dinner, scale was a bit off, so might need to adjust that - hatch scale was 6 in the drawing, I had to put it to about 0.25 to make it similar Edited October 8 by Steven P Quote
3dwannab Posted October 8 Author Posted October 8 I've noticed that the extrusion direction dxf code 210 is different on both hatches. 1 Quote
Steven P Posted October 8 Posted October 8 shouldn't have that... entmod them all to 0 extrusion? 1 Quote
3dwannab Posted October 8 Author Posted October 8 (edited) This is a testing version only but it seems to work. I wonder what CAD wizard made this mess of a detail library (vl-load-com) ;; ;; Fix the extrusuion values of hatches so they are 0,0,1 ;; ;; TESTING VERSION ;; ;; Thread here: https://www.cadtutor.net/forum/topic/92094-flatten-issue-with-drawing ;; ;; 3dwannab 2024.10.08 ;; ;; TO DO: ;; - Make this work for ENTITIES inside BLOCKS ;; (defun c:FXHatchExtrusion_To_0 (/ *error* acDoc cnt dxf210 ent entData newEntData newExtrude newExtrudeVal obj oldExtrude ss typ var_cmdecho) (defun *error* (errmsg) (and acDoc (vla-EndUndoMark acDoc)) (and errmsg (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*")) (princ (strcat "\n<< Error: " errmsg " >>\n")) ) (setvar 'cmdecho var_cmdecho) ) ;; Start the undo mark here (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object))) (or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc)) ;; Get any system variables here (setq var_cmdecho (getvar "cmdecho")) (setvar 'cmdecho 0) (if (setq ss (ssget "_:L" '((0 . "HATCH")))) (progn (repeat (setq cnt (sslength ss)) (setq cnt (1- cnt)) (setq ent (_dxf -1 (entget (ssname ss cnt)))) (setq entData (entget ent)) ; Get the entity's data list (setq obj (vlax-ename->vla-object ent)) (setq typ (cdr (assoc 0 (entget ent)))) (cond ;; Placeholder condition for other entities ; ((= typ "**") ; ) ;; end cond ;; Condition for HATCHES. ((= typ "HATCH") (setq newExtrudeVal 0.0) ; Set this to 0.0 (if (setq dxf210 (assoc 210 entData)) (progn (setq oldExtrude (cdr dxf210)) ;; Extract the current extrude components (setq newExtrude (list (nth 0 oldExtrude) newExtrudeVal (nth 2 oldExtrude))) ;; Create the new extrude with the modified Y component (setq newEntData (subst (cons 210 newExtrude) dxf210 entData)) ;; Replace the old extrude with the new extrude (entmod newEntData) ;; Apply the changes to the HATCH entity (entupd ent) ; Update the entity to reflect the change ) ) ) ;; end cond HATCH ) ) ) ;; progn ) ;; if ssget (if ss (progn (princ (strcat ">> " (itoa (sslength ss)) (if (> (sslength ss) 1) " objects extrude values are" " objects extrude value is") " fixed <<\n")) (sssetfirst nil ss) (command "_.regen") ) ) (vla-EndUndoMark acDoc) (*error* nil) (princ) ) ;; ----------------------------------------------------------------------- ;; ----------------------=={ Functions START }==-------------------------- ;;----------------------------------------------------------------------;; ;; _dxf ;; Finds the association pair, strips 1st element ;; args - dxfcode elist ;; Example - (_dxf -1 (entget (ssname (ssget) 0))) ;; Returns - <Entity name: xxxxxxxxxxx> (defun _dxf (code elist) (cdr (assoc code elist)) ) (c:FXHatchExtrusion_To_0) ;; Unlbock for testing Edited October 8 by 3dwannab 1 Quote
3dwannab Posted October 9 Author Posted October 9 Man, this drawing is a nightmare. I have this polyline with a 210 DXF of (210 0.0 0.0 -1.0) See attached. I've updated my code to include the DXF codes 220 and 230. When I run the program on this line it flips it seeing as the Z vector is -1.0. (vl-load-com) ;; ;; Fix the extrusuion values (dxf codes 210, 220 & 230) of all object so they are 0,0,1 ;; ;; TESTING VERSION - Use at your own risk ;; ;; Thread here: https://www.cadtutor.net/forum/topic/92094-flatten-issue-with-drawing ;; ;; 3dwannab 2024.10.08 ;; ;; TO DO: ;; - Make this work for ENTITIES inside BLOCKS ;; (defun c:FXExtrusion_To_0 (/ *error* acDoc cnt dxf210 ent entData newEntData newExtrude newExtrudeVal obj oldExtrude ss typ var_cmdecho) (defun *error* (errmsg) (and acDoc (vla-EndUndoMark acDoc)) (and errmsg (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*")) (princ (strcat "\n<< Error: " errmsg " >>\n")) ) (setvar 'cmdecho var_cmdecho) ) ;; Start the undo mark here (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object))) (or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc)) ;; Get any system variables here (setq var_cmdecho (getvar "cmdecho")) (setvar 'cmdecho 0) (if (setq ss (ssget "_:L" '((0 . "*")))) (progn (repeat (setq cnt (sslength ss)) (setq cnt (1- cnt)) (setq ent (_dxf -1 (entget (ssname ss cnt)))) (setq entData (entget ent)) ; Get the entity's data list (setq obj (vlax-ename->vla-object ent)) (setq typ (cdr (assoc 0 (entget ent)))) ; (setq newExtrudeVal 0.0) ; Set this to 0.0 (setq newExtrude (list 0 0 1.0)) ;; Create the new extrude with the modified Y component (if (setq dxf210 (assoc 210 entData)) (progn (princ "\ndxf210") (setq newEntData (subst (cons 210 newExtrude) dxf210 entData)) ;; Replace the old extrude with the new extrude (entmod newEntData) ;; Apply the changes to the entity (entupd ent) ; Update the entity to reflect the change ) ) (if (setq dxf220 (assoc 220 entData)) (progn (princ "\ndxf220") (setq newEntData (subst (cons 220 newExtrude) dxf220 entData)) ;; Replace the old extrude with the new extrude (entmod newEntData) ;; Apply the changes to the entity (entupd ent) ; Update the entity to reflect the change ) ) (if (setq dxf230 (assoc 230 entData)) (progn (princ "\ndxf230") (setq newEntData (subst (cons 230 newExtrude) dxf230 entData)) ;; Replace the old extrude with the new extrude (entmod newEntData) ;; Apply the changes to the entity (entupd ent) ; Update the entity to reflect the change ) ) ) ) ;; progn ) ;; if ssget (if ss (progn alloc (princ (strcat ">> " (itoa (sslength ss)) (if (> (sslength ss) 1) " objects extrude values are" " objects extrude value is") " fixed <<\n")) (sssetfirst nil ss) (command "_.regen") ) ) (vla-EndUndoMark acDoc) (*error* nil) (princ) ) ;; ----------------------------------------------------------------------- ;; ----------------------=={ Functions START }==-------------------------- ;;----------------------------------------------------------------------;; ;; _dxf ;; Finds the association pair, strips 1st element ;; args - dxfcode elist ;; Example - (_dxf -1 (entget (ssname (ssget) 0))) ;; Returns - <Entity name: xxxxxxxxxxx> (defun _dxf (code elist) (cdr (assoc code elist)) ) (c:FXExtrusion_To_0) ;; Unlbock for testing Extrusion Problem Code 210.dwg 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.