Author Topic: 3D slice challenge  (Read 4252 times)

0 Members and 1 Guest are viewing this topic.

Jimmy D

  • Guest
3D slice challenge
« on: April 12, 2005, 09:20:03 AM »
Can I put a new challenge here? I've been working on this for a few
evenings now, and it works but not always (sometimes I get a fatal error).
I think this project is something that many of us could use, so all gurus out there: give it a go!

Here's the story:

The drawing:
A BIG 3D drawing (20-30Mb) with many X-refs and blocks.
I have a *defun* that xplodes all blocks and binds all xrefs, but the binding doesn't work as it should (nested xrefs?), so the xploding and binding is done manually for now.
The drawing is of a big mechanical installation with different floors on
different heights.

What the engineers want:
A section cut just above one floor and be able to see what is there and what is
underneath the floor, but not the whole way down (e.g cut at level 5,000mm and look
1,000 mm down).

Solution (???)
Make a slice between 2 planes, activate a new layout and perform a solprof on
the reamining solids.

What have I got so far :

2 lisp files:
1st file
A rectangle is created at user input; the user specifies the depth
and a second rectangle is drawn (copied) at the specified depth (on separates layer).
Some x-data is added sothat the second lisp file can recognize them as 1 set.

2nd file
All rectangles with specific x-data are put in a list, the first rectangle
in the list is collected, the accompanying rectangle is collected,
a slice is made, layout activated, solprof performed, sliced solids removed, original solids
are inserted and the second rectangle is collected,...and everything repeats.

I hope this explanation is a little clear.

So here is the routine (without error-checking; setvar's,....)

FIRST FILE

Code: [Select]
;Create new layer:
(if (= (tblsearch "layer" "JDTC_SPS_Square") nil)
    (entmake '((0 . "LAYER")(100 . "AcDbSymbolTableRecord")(100 . "AcDbLayerTableRecord")(2 . "JDTC_SPS_Square")(70 . 0)
    (62 . 110)(6 . "CONTINUOUS"))))
(command "_layer" "t" "JDTC_SPS_Square" "set" "JDTC_SPS_Square" "")

;Create the rectangle (cutting plane)
(command "._rectangle" pause pause)
(initget 1)
(setq DVSDiepte (getreal "\nDepth of the cut..."))
(setq SPSObject1 (entlast))
(setq lastent1 (entget SPSObject1))

;Get 2 cornerpoints from the rectangle (thanks to Juerg Menzi)
   (setq VLObject (vlax-ename->vla-object SPSObject1))
   (setq ptlist (list (vlax-curve-getstartpoint VLObject)))
   (setq Teller 1.0)
   (repeat (1- (fix (vlax-curve-getendparam VLObject)))
   (setq ptlist (cons (vlax-curve-getpointatparam VLObject Teller) ptlist)
   Teller (1+ Teller)
    )
    )
   (setq ptlist (cons (vlax-curve-getendpoint VLObject) ptlist))
   (setq ptlist(reverse ptlist))
   (setq SqPt1 (nth 0 ptlist))
   (setq SqPt3 (nth 2 ptlist))

;Create second rectangle (cutting plane)
(setvar "OSMODE" 0)
(setq P1 (list 0 0 0)
      P2 (list 0 0 (* -1 DVSDIEPTE)))
(command "._copy" SPSObject1 "" P1 P2)
(setq SPSObject2 (entlast)
      lastent2 (entget SPSObject2))

;Determine the view in the layout because it has to match the rectangles (planes)
(command "ucs" "w")
(if (equal (car sqpt1)(car sqpt3) 0.001)
    (if (= (minusp DVSDIEPTE) T)(setq Zicht "Right")(setq Zicht "Left")
    )
)
(if (equal (cadr sqpt1)(cadr sqpt3) 0.001)
    (if (= (minusp DVSDIEPTE) T)(setq Zicht "Back")(setq Zicht "Front")
    )
)
(if (equal (caddr sqpt1)(caddr sqpt3) 0.001)
    (if (= (minusp DVSDIEPTE) T)(setq Zicht "Bottom")(setq Zicht "Top")
    )
)

;Create a number to strcat to the layout
;The number is saved in the drawing sothat if a layout is
;deleted, the xdata doesn't get mixed up (multiple rectangles
;with the same xdata)
(setq JDUser1 (getvar "USERI1"))
(if (= nil JDUser1)
    (Progn
    (setq Count 1)
    )
    (progn
    (setq Count (+ (getvar "USERI1") 1))
    (setvar "USERI1" Count)
    )
)


;create a new layout
(setq JDTC_SPS_Layout_name (strcat "JIDTC_SPS_Layout " (itoa count)))
(setq JDTC_SPS_Layout_nameSec (strcat "Sec" JDTC_SPS_Layout_name));for xdata
(command "_layout" "n" JDTC_SPS_Layout_name)
(command "_layout" "s" JDTC_SPS_Layout_name)
(command "_vports" "fit")
(command "mspace")
(command "_View" "O" Zicht)
(command "_layout" "s" "model")

;Create the x-data
(regapp "JIDH-XDATA-1")
(regapp "JIDH-XDATA-2")
(setq exdata1 (list "JIDH-XDATA-1"))
(setq exdata1 (append exdata1 (list (cons '1000 JDTC_SPS_Layout_name))))
(setq newent1 (append lastent1 (list (list -3 exdata1))))
(entmod newent1)
(setq exdata2 (list "JIDH-XDATA-2"))
(setq exdata2 (append exdata2 (list (cons '1000 JDTC_SPS_Layout_nameSec))))
(setq newent2 (append lastent2 (list (list -3 exdata2))))
(entmod newent2)


SECOND FILE

Code: [Select]
;Get all solids and make a block
(setq DwgModel (ssget "X" '((0 . "3DSOLID"))))
(if (= DwgModel nil)(progn
    (alert "\nno solids..!")
    (exit)))
(setq P0 (list 0 0 0))
(command "._block" "JDTC_SPS_Block" P0 DwgModel "")

;insert block
(defun GetModel ()
(command "ucs" "w")
(command "._insert" "JDTC_SPS_Block" P0 "1" "1" "0")
(command "._explode" (entlast))
(setq DwgModel (ssget "X" '((0 . "3DSOLID"))))
)
(GetModel)

;get middlepoint of the 2 rectangles (planes)
(defun MiddlePnt (Pnt1 Pnt2)
   (mapcar '(lambda (a b)
            (* 0.5 (+ a b))
             )
   Pnt1 Pnt2)
);end defun

;Get the cornerpoints of the rectangles (planes)
(defun DoTheCut (ptlista ptlistb VPName)
   (setq SqPt1 (nth 0 ptlista))
   (setq SqPt2 (nth 1 ptlista))
   (setq SqPt3 (nth 2 ptlista))
   (setq SqPt4 (nth 3 ptlista))
   (setq SqPtA1 (nth 0 ptlistb))
   (setq SqPtA2 (nth 1 ptlistb))
   (setq SqPtA3 (nth 2 ptlistb))
   (setq SqPtA4 (nth 3 ptlistb))
   (setq MidPnt (MiddlePnt SqPt1 SqPta1))
;get the block and slice
   (GetModel)
   (command "._slice" DwgModel "" SqPt1 SqPt2 SqPt3 MidPnt)
   (command "._slice" DwgModel "" SqPtA1 SqPtA2 SqPtA3 MidPnt)
   (command "._layout" "s" VPName)
   (setvar "CVPORT" 2)
;select all solids and slice + solprof
   (setq DwgModel (ssget "X" '((0 . "3DSOLID"))))
   (command "solprof" dwgmodel "" "" "" "")
   (command "._erase" dwgmodel "")
);end defun dothecut

;Get the cornerpointslist (thanks to Juerg Menzi)
(defun GetThePoints (CutField1 Count)
       (setq DvsObject (ssname  CutField1 Count))
       (setq DvsObject (vlax-ename->vla-object DvsObject))
       (setq ptlist (list (vlax-curve-getstartpoint DvsObject)))
       (setq Teller 1.0)
       (repeat (1- (fix (vlax-curve-getendparam DvsObject)))
       (setq ptlist (cons (vlax-curve-getpointatparam DvsObject Teller) ptlist)
       Teller (1+ Teller)
       )
       )
       (setq ptlist (cons (vlax-curve-getendpoint DvsObject) ptlist))
       (setq ptlist(reverse ptlist))
);end defun Getthepoints

;Retrive the x-data
(setq CutField1 (ssget "X" '((-3 ("JIDH-XDATA-1")))))
(setq CutField2 (ssget "X" '((-3 ("JIDH-XDATA-2")))))
(setq CutField1Length (sslength CutField1))
(setq CutField2Length (sslength CutField2))



;iterate thru the rectangles (planes)
(setq Count 0)
(repeat CutField1Length
   (setq ptlistA (GetThePoints Cutfield1 Count))
   (setq SPSObject (entget (ssname  CutField1 Count)'("JIDH-XDATA-1")))
   (setq VPName (cdr (assoc 1000 (cdr (cadr (assoc -3 (cdr SPSObject)))))))
   (setq VPNameSearch (strcat "Sec" VPName))
   (setq CountA 0)
   (repeat CutField2Length
       (setq SPSObjectA (entget (ssname  CutField2 CountA)'("JIDH-XDATA-2")))
       (setq VPNameA (cdr (assoc 1000 (cdr (cadr (assoc -3 (cdr SPSObjectA)))))))
       (if (= VPNameA VPNameSearch)(setq ptlistB (GetThePoints Cutfield2 CountA)))

       (setq CountA (+ CountA 1))
   );end repeat
   (DoTheCut ptlista ptlistb VPName)
   (setq Count (+ Count 1))
);end repeat


Let me hear something from all you Lisparians (is that a word?) out there!!

Columbia

  • Guest
3D slice challenge
« Reply #1 on: April 12, 2005, 09:59:04 AM »
I built a function similar to what you want (not the exploding/binding part but the sectioning) and got it to work really well.  I can't put the code up, unfortunately, due to propietary licensing issues from my company.  But I will try to help you out a little.  The biggest tip I can give you right now, is to stay away from slice and try to use Interfere.   Slicing ends up being more work than is absolutely necessary.  There are cool options with interfere that will allow you build a solid(s) that intersects with each another.  Go in that direction and see what you can come up with...

Jimmy D

  • Guest
3D slice challenge
« Reply #2 on: April 12, 2005, 10:02:19 AM »
Thanks Newt

I think you have a point there, I just realised that solids above or under the slice plane are not selected and therefore are not removed! So that won't do.
I'll have a look at the intersect option.

CADaver

  • Guest
3D slice challenge
« Reply #3 on: April 13, 2005, 11:48:10 AM »
Let's think about this from a whole new direstion.  We are exclusively 3D and have chosen to use DVIEW (customized) to view "slices" 3D models.  Below is a ham-handed function that we started with to make DVIEW slices of 3D models.  I'm at home now and don't have access to the "improved" function.  The sliced views can be saved with the VIEW command for recall later.  It works for all objects without exploding or binding or whatever, and is a "live" as the xrefs are.

I'm quite sure that MP or CAB or one of the other real lisp gurus here could improve on this radically.

Code: [Select]
;------------------------------------------------------------------
; original from CADaver with help from Mark Thomas
; modifications and viewport change function by ruul morawetz
; requires UNDO on
; v0.4 last edit 03/11/24
;------------------------------------------------------------------
(setq *dvsdeep* 12.0) ; default section depth
;------------------------------------------------------------------
(defun c:dvs ( / *error*)

   (defun *error* (msg)
      (cond
         (msg (command)(command)(princ (strcat "\nError: " msg)))
         (T nil)
      )
      (dvs:restore)
      (if msg (command "_u"))
   )
   (defun dvs:save ( / n)
      (setq *dvs* nil)
      (command "_undo" "_begin")
      (foreach n '("CMDECHO" "WORLDVIEW" "UCSFOLLOW" "EXPERT")
         (setq *dvs* (cons (cons n (getvar n)) *dvs*))
      )
   )
   (defun dvs:restore ()
      (foreach n *dvs*
         (setvar (car n) (cdr n))
      )
      (command "_undo" "_end")
   )
   (dvs:save)
   (if (not *dvsdeep*) (setq *dvsdeep* 12.0))
   (dvs:section)
   (*error* nil)
   (prin1)
)
;------------------------------------------------------------------
(defun dvs:section (/ pt1 pt2 ang Ndvsdeep)
   (setvar "EXPERT" 5)
   (setq curvp (getvar "cvport"))
   (command "_ucs" "_s" "__TMP")
   (command "_ucs" "_v")
   (cond
      ((null (setq pt1 (getpoint "\nSelect Centerpoint of Section: "))))
      ((null (setq ang (getangle pt1 "\nEnter Viewing Point Angle from Section: "))))
      ((null (setq pt2 (polar pt1 ang 12))))
      ((null  
         (if (setq Ndvsdeep
            (getdist (strcat "Enter Depth of Section: <" (rtos *dvsdeep*) ">: ")))
            (setq *dvsdeep* Ndvsdeep) T)))

      (T
         ;(command "_.undo" "_begin") ; moved to calling function
         (setq pt1 (trans pt1 1 0) pt2 (trans pt2 1 0))
;        (command "_ucs" "_w") ; moved down

         (prompt "\n Select Viewport for Section Display (ENTER if necessary then) ")
         (dvs:rm:cvpc)     ; vp-change function (possibly unreliable)
         ;(getstring)  ; simple and works

         (setvar "WORLDVIEW" 1)
         (setvar "UCSFOLLOW" 0)
         (command "_ucs" "_w") ; moved here (only necessary after viewport change)
         (command "_.dview" "" "_po" "_non" pt1 "_non" pt2 "_cl" "_f" (* *dvsdeep* 0.5) "_cl" "_b" (- 1.0 (* *dvsdeep* 0.5)) "")
         (command "_.zoom" "_e" "_.zoom" ".8x")
         (setvar "cvport" curvp)
         (command "_ucs" "_r" "__TMP" "_ucs" "_d" "__TMP")
      )
   )
)
;------------------------------------------------------------------
; ruul 03/11/11 - Crazy ViewPort Change
; adjust trigger if needed
; endless loop until clicked in another viewport
; if trigger isn't sufficient, enter also breaks the loop
(defun dvs:rm:cvpc ( / grrd weida p pold viewsize trigger)
   (setq weida T viewsize (getvar "VIEWSIZE")
         trigger (* viewsize 0.4)) ; adjust factor according to mouse speed etc
   (while weida
      (setq grrd (grread T )) ;(+ 1 2 4 8) 2
      (cond
         ((= 5 (car grrd))
            (setq p (cadr grrd))
            (cond
               ((and pold (> (distance p pold) trigger))
                  (setq weida nil)
               )
            )
            (setq pold p)
         )
         ((= 2 (car grrd))(setq weida nil))
         (T nil
         )
      )
   )
)
;------------------------------------------------------------------
(princ  "\nDVSection loaded. call with DVS. ")
;------------------------------------------------------------------
(prin1)
;------------------------------------------------------------------

Jimmy D

  • Guest
3D slice challenge
« Reply #4 on: April 14, 2005, 05:58:55 AM »
Cadaver

I've had a look at the DVS routine. It's a nice routine but it doesn't make slices, it only "obscures" part of the screen.

This means that it is not possible to see (or generate) hidden lines, and that is exactly what I would like to do.

I think the way to go is:
a) make a solid that represents the "slice"-field.
b) Use the interfere-command (as proposed by Columbia).
As a bonus we then don't have to cut the whole way thru, but we can make selected cuts in irregular shapes.

I've had a try with interfere and it seems promissing, but I have the next problem (from the Acad Help-files):


Quote
If there are more than two interfering 3D solids, it may not be clear which pairs are interfering if all the interfering 3D solids are highlighted at once.

Highlight pairs of interfering solids? [Yes/No] <N>: Enter y or n, or press ENTER

If there is more than one interfering pair, AutoCAD displays the following prompt:

Enter an option [Next pair/eXit] <Next>: Enter x or n, or press ENTER



So Autocad doesn't always prompt for 'Highlighting?(Y/N)'.
how can I overcome this in the program, because I don't know how many solids are selected that interfere?

CADaver

  • Guest
3D slice challenge
« Reply #5 on: April 14, 2005, 03:25:36 PM »
Quote from: Jimmy D
Cadaver

I've had a look at the DVS routine. It's a nice routine but it doesn't make slices, it only "obscures" part of the screen.

This means that it is not possible to see (or generate) hidden lines, and that is exactly what I would like to do.
Wrong thinking again.  Use viewports to display the slice and make them plot hidden.  Set OBSCUREDLTYPE = 2 or 4 and OBSCUREDCOLOR to something pleasing for your plots.


Quote from: Jimmy D

I think the way to go is:
a) make a solid that represents the "slice"-field.
b) Use the interfere-command (as proposed by Columbia).
As a bonus we then don't have to cut the whole way thru, but we can make selected cuts in irregular shapes.

I've had a try with interfere and it seems promissing, but I have the next problem (from the Acad Help-files)
...

As long as you NEVER plan on using anything except 3dsolids (like xrefs, blocks, surfaces), this round-about method may be worth the effort.  I don't think so.  The direction of the industry is 3D.  Viewing the 3Dmodel itself (not some hacked up facsimile) will be necessary.  Learning those tools now will only increase the ease at which the change takes place.

We've been exclusively 3D for several years now, and we've tried several different options.  DVIEW clipping the model has been, by far, the most productive we've found.

Jimmy D

  • Guest
3D slice challenge
« Reply #6 on: April 15, 2005, 01:33:00 AM »
Cadaver,

You're right (as always), I forgot the OBSCURELTYPE function.

For us this is the first time we do a project in 3D that is so big (+ 110Mb at the moment). We are also still on ACAD2002 (with Mechanical 6 but that is not much of a help).

Aahh, decisions, decisions,...

Well, back to the drawing board.....

CADaver

  • Guest
3D slice challenge
« Reply #7 on: April 15, 2005, 11:27:49 AM »
Quote from: Jimmy D
Cadaver,

You're right (as always), I forgot the OBSCURELTYPE function.

For us this is the first time we do a project in 3D that is so big (+ 110Mb at the moment). We are also still on ACAD2002 (with Mechanical 6 but that is not much of a help).
We are still using R2002 for most of our work as well.  We only have a couple of projects up to R2005, and they're pretty small.  Our average model runs in the 90Mb range and we often get some ugly thing that's well over 110Mbs.  The best medicine for that is RAM, RAM, and some more RAM.  I'm running 1Gb at home and 1.5Gb at work.  Both machines are striped of any other functionality, they only do AutoCAD, with Excel and Word loaded without "Office" (I've loaded notepad++ and Crimson on the work machine).

BTW, does anyone have an AutoLISP plug-in for Crimson laying around?



Quote from: Jimmy D
Well, back to the drawing board.....
Only when they pry the mouse out of my cold dead fingers.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
3D slice challenge
« Reply #8 on: April 15, 2005, 11:36:37 AM »
AutoLISP syntax file for AutoLISP
 
Zip file.

I've no idea if it's any good Randy, I found it doing a quick search.
Engineering Technologist CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

CADaver

  • Guest
3D slice challenge
« Reply #9 on: April 15, 2005, 11:39:49 AM »
Thanks Michael, I'll give it a try.

Anybody else using Crimson?? or Notepad++??

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
3D slice challenge
« Reply #10 on: April 15, 2005, 11:45:58 AM »
I looked at the files Randy; they're lame.

However, given the structure that's provided I can update them for you, as I'm just in the process of updating my Textpad syntax files. They will be Vanilla LISP, DOSLib and ACET conversant up to AutoCAD 2006 when complete.

Give me a day or so, lot's on the fire.
Engineering Technologist CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

Columbia

  • Guest
3D slice challenge
« Reply #11 on: April 15, 2005, 12:01:02 PM »
I would just like to interject the following, although I'm trying hard not to step on anybody's toes.

The clipping option is very cool, but it's not an end all to be all.  For instance, if some company is using CAM software to define cut and tool paths in CNC, most of all those softwares need 2D vector drawings of some kind, either home grown within it's own app, or an imported on like DXF.  Sure you could, set up the clipping planes using DVS or whatever, and plot to PNG or DWF or some other non-intelligent vector format, and then try to find another utility to convert that file over to an acceptable format, but that again doesn't catch all conditions and also introduces outside errors due to translation.

Now I'm not saying that using the interfere command is the best thing out there either, but there are circumstances when entity manipulation is the only way to go.  And that should not be discounted.  I could go on forever to no good end, and argue until I turn blue, but what good would that do? :roll:

CADaver

  • Guest
3D slice challenge
« Reply #12 on: April 15, 2005, 03:04:41 PM »
Quote from: MP
I looked at the files Randy; they're lame.

However, given the structure that's provided I can update them for you, as I'm just in the process of updating my Textpad syntax files. They will be Vanilla LISP, DOSLib and ACET conversant up to AutoCAD 2006 when complete.

Give me a day or so, lot's on the fire.
No hurry, I was just looking fer a shortcut.  Don't go out of your way on my account.

CADaver

  • Guest
3D slice challenge
« Reply #13 on: April 15, 2005, 03:27:04 PM »
Quote from: Columbia
I would just like to interject the following, although I'm trying hard not to step on anybody's toes.
Don't bother, my toes are armor-plated.

Quote from: Columbia
The clipping option is very cool, but it's not an end all to be all.  For instance, if some company is using CAM software to define cut and tool paths in CNC, most of all those softwares need 2D vector drawings of some kind,
okay let me stop you right here.  If you're talkin' about some backwater shop with antiquated hardware and software for CNC, you may have a point.  My position on those guys is either keep up or twist in the wind.  Makes me no never-mind either way.  I do a considerable amount of CNC work on the side for a valve fab shop.  They neither need nor want some facsimile of the model, they want the actual model.  They want exactly what it is they are going to machine.  But then again, these guys are using software that was written in the last 3 years and keep their hardware up to date with the latest software.

So your argument here is just so much smoke.


Quote from: Columbia
Now I'm not saying that using the interfere command is the best thing out there either, but there are circumstances when entity manipulation is the only way to go.  And that should not be discounted.
Oh, I can TOTALLY discount that as an option for drawing production, and as I've pointed out above, I can discount its use for CNC as well.  While the INTERFERE command has its place in the creation of the piece while building the model, that is about the limit of its real use.


Quote from: Columbia
I could go on forever to no good end, and argue until I turn blue, but what good would that do? :roll:
Oh, do go on.  But first, understand this is not my first rabbit hunt with this topic, and, at the very least, I'm just a little familiar with it.

And Oh, take nothing I say personally.  It is never my intent to cast aspersions upon the holder of an idea... ...just the idea itself.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
3D slice challenge
« Reply #14 on: April 16, 2005, 02:44:12 PM »
Quote from: CADaver
No hurry, I was just looking fer a shortcut.  Don't go out of your way on my account.

See zip file.

It's a near 100% translation from my textpad syntax file. I've no idea if crimson can handle the volume defined by this file, but ya don't know unless ya try.

If it can't load it perhaps we could strip some stuff out like the constants section (which is not tiny).

Cheers.
Engineering Technologist CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst