Author Topic: Problem with some regions exploded from 3d-bodys processed with Superflatten  (Read 13491 times)

0 Members and 1 Guest are viewing this topic.

peterba

  • Guest
Hello all,

this is my first post here.
I live in Germany and i hope my English is not to bad.
I use lisp since a long time and solved some problems in autocad with it.
I found Superflatten 1.1a anywhere a few months ago and after some checks i mention that it is the best program around.
Thank you Joe for this exceptional program.

Now i noticed, that there is a new release 1.2e. I inspected the code and made some tests with drawings in autocad.
I fixed some lines for use in local autocad versions and added an error control in function "FlatRegion".
You find the lines marked as:
Quote
;; *** Modification by pb

My test drawing "Pumpe1.dwg" contains one 3DSOLID. With my changes superflatten processes without any error but leaves some objects unflattened.
The other point is, that some flattended parts have lost details (for instance border lines).
(AutoCAD 2009)

Hope, somebody can give a suggestion.

kind regards
Peter B.

Joe Burke

  • Guest
Hi Peter,

Welcome to theswamp. Your English sounds good to me.

I'm glad to hear you found SuperFlatten useful.

I haven't studied your code changes or example file yet, but I will over the weekend.

Regards
Joe Burke

Joe Burke

  • Guest
Peter,

I looked at the internationalization changes you made. Good catch. I thought all of that had been caught before, but obviously not. I will issue a new version which includes those changes.

Regarding your change to the FlatRegion sub-function, agreed, it avoids a potential error given your example file. I will incude your changes in the next version with credit to you for those changes.

Obviously SF is a very complicated routine. I've often thought it's strange I've received no problem reports similar to yours.

At the same time, the routine has always worked well for me when dealing with the types of files which it was designed to fix.

More later...


Joe Burke

  • Guest
Peter and admin folks,

I've updated the code per Peter's bug report to SuperFlatten version 1.2f, but I'm not sure where to post it. The original SF topic started by me is in Show Your Stuff. There is also a SuperFlatten topic in AutoLISP (Vanilla / Visual) where I posted revised versions.

Should these two topics be combined? Plus we have this new related topic by Peter. Please advise.
« Last Edit: November 27, 2010, 06:44:17 AM by Joe Burke »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>

I'd post the 'f' build in Show your stuff but leave the prev build there ie just add the new zip attachment in the first post.
Then I'd add a note/link to S.Y.S.  in any other posts that have a build.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Joe Burke

  • Guest

I'd post the 'f' build in Show your stuff but leave the prev build there ie just add the new zip attachment in the first post.
Then I'd add a note/link to S.Y.S.  in any other posts that have a build.


Hi Kerry,

I'd prefer to have all messages related to the routine moved to the original topic in Show Your Stuff. The header comments within the routine point there.

;; Please send bug reports to me directly at lowercase@hawaii.rr.com
;; or post to the SuperFlatten topic at theswamp under "Show your stuff".

Obviously if the rouine is posted elsewhere, there should be only one place to look here for the latest version.

Likewise, older versions should not be available here.
« Last Edit: November 29, 2010, 06:10:20 AM by Joe Burke »

peterba

  • Guest
Hi Joe,

thank you for reply - and the nice words  :wink:

I agree with you that there should be only one location to store and find the newest version of SF.
But I'm new here an will follow your rules.

Until now, the problem like in the sample file (Pumpe.dwg) only rarely occurs. But this 3D solid object is only a little part of a larger 3D plant design.
Most of the body objects lose details after "SF" because of the internal use of "explode".
I have played around with the express tools "flatten" and noticed that the method used there (WMF out/in) gives me a better result for the 3D objects.
Therefore i included the call to the ET sub-function "acet-wmf-convert"  in your Superflatten and a few additional code for handy use.

I'd like to show you my draft of this version. But how? Just another attachment or personal message?

Peter

Joe Burke

  • Guest
Hi Peter,

I guess you should post your WMF in/out code in this topic for now so others who may be interested can test it. Where the current SF version ultimately resides can be left to future discussion.

You are probably aware the WMF in/out method tends to loose accuracy. I reserve judgement until I test your code.

Thanks for your help.

Joe Burke

  • Guest
Peter,

Attached is an example file of the types of problems SF was originally designed to fix. How it deals with the types of objects you mentioned was an after-thought, simply intended to make the routine more complete.

Joe Burke

  • Guest
Also, try running ET flatten command on the exmple file. It fails/errors due to some poor code.

peterba

  • Guest
Joe,
attached is your SF with my code parts: marked with "*** Modification by pb"

the main altered parts are:
Code: [Select]
  ;; *** Modification by pb ***
  ;; new function for 3D objects
  ;; if Expresstools loaded use WMFout/in in acet-wmf.lsp
  (defun Flat3D (obj / ss)
    (if acet-wmf-convert
      (progn
(princ
  (strcat "\rEinebnen der Auswahl (Element: "
  (substr objname (+ 3 (vl-string-search "Db" objname)))
  "), bitte warten... "
  (setq *sbar (Spinbar *sbar))
  "\t"
  )
)

;; save the original view
(if (not (tblsearch "view" "zztemp"))
  (progn
    (command "._view" "_s" "zztemp")
    (command "._ucs" "_w")
  )
)
;; set to top view without perspective
(setvar "perspective" 0) ;Parallelansicht = ohne Perspektivansicht
(command "._view" "_o" "_t")

;; Definiert ein neues Koordinatensystem, dessen XY-Ebene senkrecht
;; zur Blickrichtung liegt (parallel zum Bildschirm).
;; (acet-ucs-cmd (list "_view"))
 
;;Parameter für WMFout/in
;; 3= scale each object to max size possible before wmf
(setq ss (acet-wmf-convert
   (list (ssadd (vlax-vla-object->ename x)) 3 nil nil)
)
)

(if ss
  (progn
    ;; flatten was succesful
    ;; kill source object
    (vla-delete obj)
    ;; Idee:
    ;; Neuen Auswahlsatz in neuem Block zusammenfassen
    ;; Objekttyp + "_flattend_" + "Objektname
    ; .....
  )
  ;; if not succesful, try explode
  (CommandExplode x)
)
;; set previous coordinate system
(acet-ucs-cmd (list "_p"))
      )
      ;; do explode in case of ET not loaded
      (CommandExplode x)
    )
  ) ; _end of new function Flat3D *** Modification by pb

call of Flat3D:
Code: [Select]
           ((or
       (eq "AcDb3dSolid" objname)
       (eq "AcDbSurface" objname)
     )

      ;; *** Modification by pb ***
      ;; new function Flat3D - use WMFout/in
      ;; (more details but less precision than CommandExplode)
      ;; maybe add a condition with user decision wich
      ;; method preferable
      (Flat3D x)

    )
load ET helper function:
Code: [Select]
;; *** Modification by pb ***
;; In the case of Expresstools installed, use WMFout/in in acet-wmf.lsp
(if (findfile "acet-wmf.lsp")
  ;;(load "acet-wmf.lsp" "Konnte ET-Hilfsprogramm nicht laden!")
  (princ (load "acet-wmf.lsp" "Could not load help function of Expresstools!"))
)
(princ)
... and some variables save and restore

I tried it on your file without errors. because therein are not 3dsolid objects?
Program message: "Number of objects in model space before: 23581 after: 23579"
Result looks flattend as expected.

I know that ET flatten crashes in some files.
To avoid this i implemented only the subfunction "acet-wmf-convert". This function makes something else that i don't understand and takes some longer time, but it works fine for me.

Improvements could be:
- a user question, which method to use for 3d objects
  decide:  Explode with the risk of loosing details OR WMFout with loosing precision
- include the code for WMFout/in similar to the ET function "acet-wmf-convert" without extra subroutines

Joe Burke

  • Guest
Hi Peter,

I will need some time to study your WMFIn/Out suggestion. At first glance, using your Pump example file for testing, it looks like an excellent idea. The fact some precision is lost in the process is far outweighted by the fact data is not lost and everything is flattened, unlike the current SF version which uses the explode command.

Question, what version of ACAD are you using? I'm using vanilla 2008. In 2008 the WMFIN and WMFOUT calls are native ACAD commands. IOW, ExpressTools is not required. I don't know when these commands moved from ET to ACAD. The ExpressTools folder within 2008 still contains the acet-wmf.lsp routine your code calls.

Just food for thought at this point...

I agree there should be an option presented to the user to use WMF or explode when these types of objects are involved. As you probably know, the routine already does some checking up front to determine what types of objects were selected, before it processes the objects.

BTW, speed is not an issue in my nind. It may take a very long time to process deep nested blocks as is.

Thanks
« Last Edit: December 01, 2010, 08:27:07 AM by Joe Burke »

peterba

  • Guest
Hi Joe,
I'm using pure ACAD 2009. You' right: the Commands WMFIN and WMFOUT are build in.
I think these commands where not an invention of ExpressTools but they are used within their programmes.

The essence of ET function "acet-wmf-convert" seems to be "acet-wmf-round-trip" with the lines:
Code: [Select]
(acet-safe-command T T (list "_.wmfout" tmp ss ""))
...
(acet-safe-command T T (list "_.wmfin" tmp x "2" "2" "0"))
tmp=temporary file name
ss=current selection set
x=insert point (of the ss?)
This could be done with (command _.wmfout ...) in the same manner (filedia=0!) while rejecting the ET functions.

I'm afraid of some more questions to solve. I understand that you need more time to explore the WMFout/in method and would be very happy if you find a working release. In the meantime i can use the modified SF.
Perhaps somebody can help...

Nevertheless many thanks for your assistance.

Joe Burke

  • Guest
Hi Peter,

I think the WMFOUT and WMFIN commands have been around for a long time.

I would prefer as little reliance on acet functions as possible because old ACAD versions (2002?) did not ship with ExpressTools. Plus there's the possibilty with recent versions that the user chose not to install ET for some reason.

Looking at the code, I'm reminded of the Flatshot command which was new in ACAD 2007. Check this link which explains the Flatshot and XEdges commands.

http://www.autodeskpress.delmar.cengage.com/resources/olcs/acad2007/feb07/

Of course the Flatshot command cannot be called within SuperFlatten because there's a dialog involved and no command line version of the command. I just mention it because I'd probably use it to flatten 3DSolid objects when full accuracy is a concern.

Also note the ActiveX Export and Import methods. I haven't tried them, but Export can export a selection set of objects to a WMF file according to the documentation.

Regards

peterba

  • Guest
I have played with a new function for WMFout and WMFin for use as an alternative flatten method:
(it's the first draft)
Code: [Select]
;;; WMFTest.lsp
;;;
;;; Description:
;;; 1.) user selects the objects in current view
;;; 2.) export selection in temporary WMF
;;; 3.) import WMF as flat block reference on same position but with Z=0
;;;
;;; Intention: new WMFout/in help function for J.B.s SuperFlatten
;;;
(defun C:WMFtest ( / doc ss-name ss tmp tmpwmf targetpnt width height inspnt blkref)

  (VL-LOAD-COM)
 
  ;; Dokument
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))

  ;; Auswahlsatz
  (setq ss-name "WMFtest_ss")
  ;; kill last selection if exist
  (if (not (vl-catch-all-error-p
     (setq ss (vl-catch-all-apply
'vlax-invoke-method
(list (vla-get-SelectionSets doc) 'Item ss-name)
      )
     )
   )
      )
    (vla-Delete ss)
  )
  ;; create VLA-SelectionSet and add user selection
  (setq ss (vlax-invoke-method (vla-get-SelectionSets doc) 'Add ss-name))
  (vla-SelectOnScreen ss)

  (if (< 0 (vla-get-count ss))
    ;; selection set is not empty
    (progn
      ;; get a temp filename
      (setq tmp    (vl-filename-mktemp nil nil nil) ;without extension
    tmpWMF (strcat tmp ".WMF")
      )

      ;; WMFout
      ;; automatic generation of insertion point: top left corner of view???
      (vlax-invoke-method doc 'Export tmp "WMF" ss)

      ;; Not sure how to generate the correct insertion point for import???
      ;;
      ;; trying with the target coordinates of the current viewport...
      (setq targetpnt (vlax-safearray->list ;gibt eine Koordinatenliste zurück
(vlax-variant-value ;holt Safearray aus Variant
  (vla-get-Target (vla-get-ActiveViewport doc))
)
      )
      )
      (setq width (vla-get-Width (vla-get-ActiveViewport doc))) ;Fensterbreite
      (setq height (vla-get-Height (vla-get-ActiveViewport doc))) ;Fensterhöhe

      [color=red];; generate Safearray for insertion point
      (setq inspnt (vlax-make-safearray vlax-vbDouble '(0 . 2)))

      ;; calculate coordinates for new insertion: top left corner
      ;; ??? how do this ???
      (vlax-safearray-put-element inspnt 0 (- (car targetpnt) (/ width 2)))
      (vlax-safearray-put-element inspnt 1 (+ (cadr targetpnt) (/ height 2)))
      (vlax-safearray-put-element inspnt 2 0) ;setzt Z=0
      (setq inspnt (vlax-make-variant inspnt)) ;macht Variant aus Safearray[/color]

      ;; WMFin
      (if (findfile tmpWMF)
(progn
  (setq blkref (vla-Import doc tmpWMF inspnt 2))
  (vl-file-delete tmpWMF)
)
      )
    )
  )

  ;; delete selection set - but not the objects
  (vla-Delete ss)
 
  (princ)
)
It should insert the WMF file objects at the same position as the selection set from where it was created.
But it don't works - see the red code above!

You can try it with any drawing or with the attached file.
Any suggestions?

Greets ... and have a nice weekend!