Author Topic: height of lowest surface in 3dsolid?  (Read 4558 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Water Moccasin
  • Posts: 2123
  • Marko Ribar, architect
Re: height of lowest surface in 3dsolid?
« Reply #15 on: August 28, 2011, 12:59:27 PM »
More precise version, but if it brakes, please repeat procedure...

Code: [Select]
(defun c:npt3DS nil (c:nearestpointto3DSolid))
(defun c:nearestpointto3DSolid ( / aobj adoc mspc pt radpt rad scfn obj1 obj2 obj1e obj11 obj22 obj3 ptn radn )
  (vl-load-com)
  (setq aobj (vlax-get-acad-object)
        adoc (vla-get-activedocument aobj)
        mspc (vla-get-modelspace adoc)
  )
  (setq pt (getpoint "\nPick point from witch to calculate nearest point to 3DSolid")
        radpt (getpoint pt "\nPick point of radius of close sphere from witch to start calculation")
        rad (distance pt radpt)
  )
  (setq obj1
    (vla-addSphere mspc (vlax-3d-point pt) rad)
  )
  (defun dobj2 nil
    (if
      (not
        (vl-catch-all-error-p
          (vl-catch-all-apply 'vlax-ename->vla-object
            (list
              (setq obj2
                (car
                  (entsel "\nSelect 3DSolid for finding closest point to picked one at start")
                )
              )
            )
          )
        )
      )
      (setq obj2 (vlax-ename->vla-object obj2))
      (progn
        (prompt "\nWrong selection - nil selection - try once again")
        (dobj2)
      )
    )
  )
  (dobj2)
  (defun booleanint ( n / k scf )
    (if (= n 1) (setq scf 1.1))
    (if (= n 2) (setq scf 1.01))
    (if (= n 3) (setq scf 1.001))
    (if (= n 4) (setq scf 1.0001))
    (if (= n 5) (setq scf 1.00001))
    (setq obj22 (vla-copy obj2))
    (setq k 0)
    (while
      (vl-catch-all-error-p
        (vl-catch-all-apply
          'vla-Boolean
          (list obj1 acintersection obj2)
        )
      )
      (setq k (1+ k))
      (setq obj1e (vlax-vla-object->ename obj1))
      (vl-cmdf "_.scale" obj1e "" pt scf)
    )
    (setq obj2 obj22)
    (if (= n 1) (setq scfn 1.0))
    (if (= n 5) (setq scfn (* scfn (expt scf k))) (setq scfn (* scfn (expt scf (- k 1)))) )
    (setq obj1
      (vla-addSphere mspc (vlax-3d-point pt) rad)
    )
    (setq obj1e (vlax-vla-object->ename obj1))
    (vl-cmdf "_.scale" obj1e "" pt scfn)
  )
  (booleanint 1)
  (booleanint 2)
  (booleanint 3)
  (booleanint 4)
  (booleanint 5)
  (setq obj11 (vlax-ename->vla-object obj1e))
  (setq obj22 (vla-copy obj2))
  (vl-cmdf "_.intersect" (vlax-vla-object->ename obj11) (vlax-vla-object->ename obj22) "")
  (setq obj3 (vlax-ename->vla-object (entlast)))
  (setq ptn
    (vlax-safearray->list
      (vlax-variant-value
        (vla-get-Centroid obj3)
      )
    )
  )
  (prompt "\nNearest point on selected 3DSolid from point picked at start is : ")
  (princ ptn)
  (prompt "\nNearest distance to selected 3DSolid from point picked at start is : ")
  (princ
    (setq radn (distance pt ptn))
  )
  (vla-addSphere mspc (vlax-3d-point pt) radn)
(princ)
)
(prompt "\nShortcut to c:nearestpointto3DSolid is c:npt3DS")
(princ)

Regards, M.R.  8-)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2123
  • Marko Ribar, architect
Re: height of lowest surface in 3dsolid?
« Reply #16 on: December 31, 2011, 08:36:06 PM »
This should also work, and it is also not 100% accurate... I can't compile c# code (maybe if devo could post *.dll)

Code: [Select]
(defun solution ( pt ptn obj / rad obj1 obj2 ptnn lin ptt reg ss ape k ptnnn radn )
  (if (not obj2) (setq obj2 obj))
  (setq rad (distance pt ptn))
  (command "_.SPHERE" pt rad)
  (setq obj1 (entlast))
  (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-Boolean (list (vlax-ename->vla-object obj1) acintersection (vlax-ename->vla-object obj2)))))
  (progn
  (command "_.CHANGE" obj1 "" "p" "c" "1" "")
  (setq ptnn
    (vlax-safearray->list
      (vlax-variant-value
        (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-Centroid (list (vlax-ename->vla-object obj1)))) (vlax-3d-point ptn) (vla-get-Centroid (vlax-ename->vla-object obj1)))
      )
    )
  )
  (command "_.LINE" pt ptnn "")
  (setq lin (entlast))
  (setq ptt (polar ptnn (+ (angle pt ptnn) (/ PI 2.0)) 1.0))
  (command "_.SECTION" obj1 "" "3p" pt ptnn ptt)
  (while (eq 1 (logand 1 (getvar 'cmdactive))) (command ""))
  (setq reg (entlast))
  (if (eq (cdr (assoc 0 (entget reg))) "REGION")
    (progn
      (command "_.EXPLODE" reg "")
      (setq ss (ssget "_P"))
      (setq ape (getvar 'aperture))
      (setvar 'aperture 25)
      (command "_.TRIM" ss "" "C" (mapcar '- ptnn (list 1e-2 1e-2 1e-2)) (mapcar '+ ptnn (list 1e-2 1e-2 1e-2)) "")
      (setvar 'aperture ape)
      (repeat (setq k (sslength ss))
        (entdel (ssname ss (setq k (1- k))))
      )
    )
  )
  (setq ptnnn (cdr (assoc 11 (entget lin))))
  (entdel lin)
  )
  (progn
  (entdel obj1)
  (setq obj1 (entlast))
  (setq ptnn
    (vlax-safearray->list
      (vlax-variant-value
        (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-Centroid (list (vlax-ename->vla-object obj1)))) (vlax-3d-point ptn) (vla-get-Centroid (vlax-ename->vla-object obj1)))
      )
    )
  )
  (if (< (distance pt ptn) (distance pt ptnn)) (setq ptnn ptn))
  (command "_.LINE" pt ptnn "")
  (prompt "\nNearest point on selected 3DSolid from point picked at start is : ")
  (princ ptnn)
  (prompt "\nNearest distance to selected 3DSolid from point picked at start is : ")
  (princ
    (setq radn (distance pt ptnn))
  )
  (sssetfirst nil (ssget "_X" '((0 . "3DSOLID") (62 . 1))))
  )
  )
  (if (not (and (equal ptnn ptn 1e-8) (equal ptnn ptnnn 1e-6)))
    (if ptnnn (solution pt ptnnn obj1))
    (progn     
    (command "_.LINE" pt ptnn "")
    (prompt "\nNearest point on selected 3DSolid from point picked at start is : ")
    (princ ptnn)
    (prompt "\nNearest distance to selected 3DSolid from point picked at start is : ")
    (princ
      (setq radn (distance pt ptnn))
    )
    (sssetfirst nil (ssget "_X" '((0 . "3DSOLID") (62 . 1))))
    )
  )
)

(defun c:npt3DS nil (c:nearestpointto3DSolid))
(defun c:nearestpointto3DSolid ( / aobj adoc mspc osm pt obj ptn )
  (setq aobj (vlax-get-acad-object)
        adoc (vla-get-activedocument aobj)
        mspc (vla-get-modelspace adoc)
  )
  (setq osm (getvar 'osmode))
  (setvar 'osmode 0)
  (setq pt (getpoint "\nPick point from witch to calculate nearest point to 3DSolid"))
  (prompt "\nPick 3DSolid")
  (setq obj (ssname (ssget "_+.:E:S:L" '((0 . "3DSOLID"))) 0))
  (vla-copy (vlax-ename->vla-object obj))
  (setq ptn
    (vlax-safearray->list
      (vlax-variant-value
        (vla-get-Centroid (vlax-ename->vla-object obj))
      )
    )
  )
  (solution pt ptn obj)
  (setvar 'osmode osm)
(princ)
)
(prompt "\nShortcut to c:nearestpointto3DSolid is c:npt3DS")
(textpage)
(vl-load-com)
(princ)

In addition, here is code on witch it is based...

Code: [Select]
(defun c:trLx3dS ( / entl ents osm ptls pt1 pt2 pt3 reg ss k )
  (prompt "\nPick line that passes through 3dSolid")
  (setq entl (ssname (ssget "_+.:E:S:L" '((0 . "LINE"))) 0))
  (prompt "\nPick 3dSolid with witch to do trim")
  (setq ents (ssname (ssget "_+.:E:S:L" '((0 . "3DSOLID"))) 0))
  (setq osm (getvar 'osmode))
  (setvar 'osmode 512)
  (setq ptls (getpoint "\nPick point on line inside 3dSolid"))
  (setvar 'osmode osm)
  (setq pt1 (cdr (assoc 10 (entget entl))))
  (setq pt2 (cdr (assoc 11 (entget entl))))
  (setq pt3 (polar pt2 (+ (angle pt1 pt2) (/ PI 2.0)) 1.0))
  (vl-cmdf "_.SECTION" ents "" "3p" pt1 pt2 pt3)
  (setq reg (entlast))
  (vl-cmdf "_.EXPLODE" reg "")
  (setq ss (ssget "_P"))
  (vl-cmdf "_.TRIM" ss "" ptls "")
  (repeat (setq k (sslength ss))
    (entdel (ssname ss (setq k (1- k))))
  )
  (princ)
)

M.R.
8-)
« Last Edit: January 01, 2012, 04:17:06 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2123
  • Marko Ribar, architect
Re: height of lowest surface in 3dsolid?
« Reply #17 on: January 01, 2012, 03:12:46 PM »
I've modified my last code I hope finally... It should work without any bugs, so if you check it and find some errors, please report me... :police:

Sincerely, M.R.
 8-)

Just checked it, and it bugs when executing from main plan view, so to get it function well turn your view to any 3D view...
M.R.
« Last Edit: January 01, 2012, 05:01:53 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube