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

0 Members and 1 Guest are viewing this topic.

ghostware

  • Guest
Flatshot standard Autocad command...
Convert a 3D solid to a 3-view 2D drawing in model space.
When you have 3D solids and regions drawings you can flat them to 2D views by using the command FLATSHOT.
It will create 2D representations

Read more: http://www.ellenfinkelstein.com/AutoCAD_tips_3D-2D_model_space.html#ixzz175MI0dqx


Joe Burke

  • 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!

Peter,

I will study your post over the weekend.

Thanks for the attempt at making it work without acet calls.

If that proves too difficult, we use the acet stuff per your previous post.
« Last Edit: December 04, 2010, 07:17:56 AM by Joe Burke »

Joe Burke

  • Guest
Hi Peter,

Please check me on this.

While testing your SuperFlatten_1.2e_pb_useWMFout.lsp I commented out the line (vla-delete obj) within the Flat3D function so the source object passed to the function is not deleted. The test file was your Pump example file. I was trying to compare the original object to the WMFin/out result.

What I'm seeing does not look correct. The flattened objects are about 25.4 times larger than the source object (likely a metric/imperial units problem) plus the flattened objects are not in the same location as the source object.

Later... I checked the INSUNITS variable in the Pump file. It is set to 4 Millimemters. After changing it to 0 Unitless the above problem did not occur. So this is something the routine needs to check and adjust as needed.
« Last Edit: December 06, 2010, 04:07:27 AM by Joe Burke »

peterba

  • Guest
@Joe
I've just read your post but have no time today. i will check it tomorrow.

Edit:
I've tried several values for INSUNITS without any influence on flattening result.
Then I've found INSUNITSDEFSOURCE and INSUNITSDEFTARGET in acad help and asserted that different values (other than 0) produces similar results as you described above.
Please consider I'm not an acad designer. Only created some tools for other folks.
If it is necessary to adjust any variables in autocad please make accordant program changes.

@ghostware
thank you for the hint.
I know this command but you can use it "only" with the dialog window and not as a call in scripts or program functions.
« Last Edit: December 07, 2010, 07:53:49 AM by peterba »

Joe Burke

  • Guest
Peter,

Try this with your Pump example file when you have some time. Note, it assumes the view is Top WCS.

Code: [Select]
(defun c:WMFInOut ( / doc ename obj ss tmp tmpwmf srcctr blkref blkctr BBCenter)
  (vl-load-com)
  ;; Get bounding box center.
  ;; Argument: vla-object.
  (defun BBCenter (obj / mn mx)
    (vla-GetBoundingBox obj 'mn 'mx)
    (mapcar '*
      (mapcar '+ (vlax-safearray->list mn) (vlax-safearray->list mx))
        '(0.5 0.5 0.5)
    )
  )

  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (if
    (and
      (setq ename (car (entsel "\nSelect 3DSolid object: ")))
      (setq obj (vlax-ename->vla-object ename))
      (eq "AcDb3dSolid" (vlax-get obj 'ObjectName))
      (setq srcctr (BBCenter obj))
      (setq ss (ssadd))
      (setq ss (ssadd ename ss))
      ;; get a temp filename
      (setq tmp (vl-filename-mktemp nil nil nil))
      (setq tmpwmf (strcat tmp ".WMF"))
    )
    (progn
      ;; WMFout
      (sssetfirst nil nil)
      (sssetfirst nil ss)
      (vlax-invoke doc 'Export tmp "WMF" (vlax-get doc 'ActiveSelectionSet))
      ;; WMFin
      (if (findfile tmpwmf)
        (progn
         (setq blkref (vlax-invoke doc 'Import tmpwmf srcctr 2.0))
         (setq blkctr (BBCenter blkref))
         (vlax-invoke blkref 'Move blkctr srcctr)
         (vl-file-delete tmpWMF)
         ;; the source object is not deleted for comparison purposes.
         ;(vla-delete obj)
        )
      )
    )
  )
  (princ)
)
« Last Edit: December 07, 2010, 07:24:30 AM by Joe Burke »

peterba

  • Guest
curious behaviour: :|
sometimes perfect and sometimes there is a second user prompt "select objects"
i believe it stops here:
Code: [Select]
...
      ;; WMFout
      (sssetfirst nil nil)
      (sssetfirst nil ss)
      (vlax-invoke doc 'Export tmp "WMF" [color=red](vlax-get doc 'ActiveSelectionSet)[/color])
When pressing only "Enter" nothing happens.
If picking anything an unvisible WMFx Block is created.

Joe Burke

  • Guest
Peter,

Keep in mind, whatever quirks which may occur within the code I posted would be fixed when it's converted to a sub-function within SF. But that's a moot point...

Take a look at the file named 3D House.dwg in ACAD Samples folder. It contains many 3DSolid objects and some 2D objecs. I used that file while testing SF.

I change the file to top view and Visual Style 2D Wireframe. If I run the code I posted and select the 3DSolid table between the two couches, the result is not correct. The WMFIN block is wrong in terms of location and scale. I'm not inclined to investigate why given the following. If I run your version of SF with the Flat3D function and select all, the file is correctly flattened.

I'm not surprised to find the function I posted failed. I suspected it might given examples other than your example file. Junk that idea.

Another observation with that file. If I use the flatshot command and place a new block in the drawing, all 2D objects are not included in the new block. Example: the door swings are 2D arcs and lost in resulting flaltshot block.

There's a lot to think about here in terms of what SF should do and what options it should offer.

Also note, the current verion of SF flattens the 3DSolid objects in the 3D House file using (command "explode"). Of course it does not work well with your Pump example file.

My thoughts at this point are as follows. Use your Flat3D function as is. Probably removed the (command "explode") idea. And if any 3DSolid or similar objects are detected in SF selection set, including those in blocks, offer an option to exit SF and suggest the flatshot command given 2007 or later.
« Last Edit: December 08, 2010, 06:17:57 AM by Joe Burke »

Joe Burke

  • Guest
Peter,

Another thought in favor of using the ExpressTools WMF functions. My testing indicates the number of objects in the active file after processing is significanty less than what happens when using the ActiveX Export and Import methods.

peterba

  • Guest
Hi Joe,
I'm not sure, if i really understand everything you wrote (because of my less English skills).

Relating to your future release of SuperFlatten I would prefere a user decision about handling of 3D objects:
- flatten with explode as processed until now
- flatten with WMFout/in as discussed here (implementing the ExpressTools function "acet-wmf-convert" or a new function is your decision)
- ignore 3DSOLIDS (and SURFACE?) with a hint at the end of SF to use AutoCAD's "flatshot" command for best results

It should be "script-able" as it is now in SF with your global options.

But, don't investigate too much in this issue. It seems not to be a general problem to others.
I can work with your super program and the decision about flatten 3D objects can be done before with the selection set.

Joe Burke

  • Guest
Hi Peter,

I've had some time recently to get into issues you raised related to the use of WMF.

If you have some time and access to the "3D House" Autodesk example file in the Sample folder, please try running your version of the SF code on that file. When I do that, ACAD 2008 consistantly crashes with a fatal error when I try to save the file after the routine ends.

I've written a new WMFOutIn sub-function which seems to work well. It does not use acet functions and it does not cause a crash when saving as above. Plus it's faster than the acet based code. I'll post after I do more testing.

Regards

peterba

  • Guest
Hi Joe,
I'm glad to see you again in this topic.

I will check my program later with the "3D House.dwg" ...
I am using ACAD 2009.
(I have to work with other things this time)

so long!
Peter

-----------------------------------------------------------
EDIT 28.01.11 (My last notice at this place as you suggested)
Have checked my SF version (with WMFOutIn) on ACAD2009:

Number of objects in model space before: 266 after: 10875
Number of objects not processed or flattened: 7
Object types not flattened: Light

Then saved as new drawing (as acad 2007 type drawing) and opened with recover (16900 objects + 8 blocks) without any errors.

in conclusion: successful flattening but worked very long (about 20 minutes in my virtual machine)

will wait for your new optimized SF version...
« Last Edit: January 28, 2011, 10:53:44 AM by peterba »

Joe Burke

  • Guest
Peter,

Take your time with testing. There's no hurry.

You might also test the 3D House file with the current SF version 1.2e. I think you'll find it does a good job and fast given the types of 3DSolid objects in that file simply using command explode. Which in turn reinforces your suggestion the routine should offer an option to use MWF when appropriate. I haven't coded that part yet.

Regards

Joe Burke

  • Guest
Peter,

I will post a beta version of SF which incorporates your WMF suggestion in the original "Show your stuff" SF topic soon.

Please do not reply to this topic in the future. Direct all comments to the orginal SF topic in "Show your stuff" so we don't have versions/comments related to the routine posted in two different forums.

Joe Burke

  • Guest
Hi Peter,

I will post a new beta version of SuperFlatten to the original SF topic in Show Your Stuff soon. It uses a new sub-function named WMFOutIn to process objects like 3DSolids and some similar object types which cannot be flattened using other methods.

It does not use ExpressTools functions. The WMFOutIn function replaces ET calls in the example code you posted.

Thanks for your help with this. I think the routine is better with these changes.

BTW, the routine is not changed in terms of what it was originally designed to do.

Regards
« Last Edit: February 25, 2011, 08:32:50 AM by Joe Burke »

Joe Burke

  • Guest
Hi Joe,
I'm glad to see you again in this topic.

I will check my program later with the "3D House.dwg" ...
I am using ACAD 2009.
(I have to work with other things this time)

so long!
Peter

-----------------------------------------------------------
EDIT 28.01.11 (My last notice at this place as you suggested)
Have checked my SF version (with WMFOutIn) on ACAD2009:

Number of objects in model space before: 266 after: 10875
Number of objects not processed or flattened: 7
Object types not flattened: Light

Then saved as new drawing (as acad 2007 type drawing) and opened with recover (16900 objects + 8 blocks) without any errors.

in conclusion: successful flattening but worked very long (about 20 minutes in my virtual machine)

will wait for your new optimized SF version...

Peter,

I'll look at this and let you know what I find.

In the mean time, try the SF beta version I posted in Show Your Stuff today and let me know how it behaves. It should be more reilable than use of ExpressTools code.

Check the new WMFOutIn sub-function near the top of the code. It does all the WMF work.

Thanks
« Last Edit: February 25, 2011, 09:23:53 AM by Joe Burke »