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

0 Members and 1 Guest are viewing this topic.

Amsterdammed

  • Swamp Rat
  • Posts: 507
  • Revit MEP 2016 Acad2013, OPEN DCL
height of lowest surface in 3dsolid?
« on: August 20, 2011, 12:04:32 PM »
Hello there,

I have some solids in my drawings that represent the ceiling of my technical equipment rooms and the beams supporting the ceiling. In an attempt to auto create shop drawings for my pipe support I want to be able to read out on each possible location in the drawing what the ceiling height is above. In other words I need to find out what height the lowest surface of the 3dsolid above is.
Any body any ideas?

Thanks Bernd
Bernd

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1540
  • Moscow (Russia)
Re: height of lowest surface in 3dsolid?
« Reply #1 on: August 20, 2011, 12:46:46 PM »
Use any of the methods:
vla-Boolean
vla-GetBoundingBox
vla-IntersectWith
vla-SectionSolid
vla-SliceSolid
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

ribarm

  • Water Moccasin
  • Posts: 2126
  • Marko Ribar, architect
Re: height of lowest surface in 3dsolid?
« Reply #2 on: August 20, 2011, 12:57:54 PM »
Code: [Select]
(defun c:T ( / oscmd boxe boxn EAboxn minpoint minpt maxpoint maxpt)
(setq oscmd (getvar "osmode"))
(setvar "osmode" 0)
(setq boxe (entsel "\nPick 3DSolid object to check its lowest hight in current UCS"))
(setq boxn (car boxe))
(setvar "osmode" 0)

(defun UCS2WCSMatrix ()
  (vlax-tmatrix
    (append
      (mapcar
'(lambda (vector origin)
   (append (trans vector 1 0 t) (list origin))
)
(list '(1 0 0) '(0 1 0) '(0 0 1))
(trans '(0 0 0) 0 1)
      )
      (list '(0 0 0 1))
    )
  )
)

(defun WCS2UCSMatrix ()
  (vlax-tmatrix
    (append
      (mapcar
'(lambda (vector origin)
   (append (trans vector 0 1 t) (list origin))
)
(list '(1 0 0) '(0 1 0) '(0 0 1))
(trans '(0 0 0) 1 0)
      )
      (list '(0 0 0 1))
    )
  )
)

(vl-load-com)
(setq EAboxn (vlax-ename->vla-object boxn))
  (vla-TransformBy EAboxn (UCS2WCSMatrix))
  (vla-getboundingbox EAboxn 'minpoint 'maxpoint)
  (vla-TransformBy EAboxn (WCS2UCSMatrix))
  (setq
   minpt (vlax-safearray->list minpoint)
   maxpt (vlax-safearray->list maxpoint)
  )
(prompt "\nLowest point hight of 3DSolid object in current UCS is : ") (princ (caddr minpt))
(setvar "osmode" oscmd)

(princ)
)

M.R.

EDIT : Sorry, I forgot to type (princ (caddr minpt)) instead of just (caddr minpt) - before modification...

Hope this now helps...
« Last Edit: August 21, 2011, 05:14:51 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Amsterdammed

  • Swamp Rat
  • Posts: 507
  • Revit MEP 2016 Acad2013, OPEN DCL
Re: height of lowest surface in 3dsolid?
« Reply #3 on: August 20, 2011, 05:54:34 PM »
Sorry MArko,

I get nil with your function

Bernd
Bernd

Amsterdammed

  • Swamp Rat
  • Posts: 507
  • Revit MEP 2016 Acad2013, OPEN DCL
Re: height of lowest surface in 3dsolid?
« Reply #4 on: August 20, 2011, 05:57:02 PM »
is there something like

vlax-curve-getClosestPointTo

for a solid? I mean what i really need i the shortest distance form a certain point to the solid
Bernd

LE3

  • Guest
Re: height of lowest surface in 3dsolid?
« Reply #5 on: August 20, 2011, 06:12:33 PM »
is there something like

vlax-curve-getClosestPointTo

for a solid? I mean what i really need i the shortest distance form a certain point to the solid

Another limitation of lisp/vlisp - no (unless someone came up with a work-around)

You can do it with the BREP API - get all the faces of your solid and then in there use i.e: AcGePoint3d closestPoint = pSurface->closestPointTo(pointToTest); ... that's available in ARX or .NET flavors only

HTH.-

« Last Edit: August 20, 2011, 06:36:53 PM by DeVo »

LE3

  • Guest
Re: height of lowest surface in 3dsolid?
« Reply #6 on: August 20, 2011, 09:47:12 PM »
I mean what i really need i the shortest distance form a certain point to the solid

Ok, I need to practice my c++ and arx coding to much c#, so got the chance to write this function:

Code: [Select]
bool compare(std::pair<double, AcGePoint3d> pairOne, std::pair<double, AcGePoint3d> pairTwo)
{
return pairOne.first < pairTwo.first;
}

static void distClosestToSolidFace(void)
{
ads_name ss, ename;
TCHAR* promptPtrs[] = { _T("Select solid: "), _T("Remove solid: ") };
resbuf *ssfilter = acutBuildList(RTDXF0, _T("3DSOLID"), RTNONE);
AcGePoint3d pt;
if (acedGetPoint(NULL, _T("\nPoint to test: "), asDblArray(pt)) !=RTNORM) return;
if (acedSSGet(_T("_:S:$"), promptPtrs, NULL, ssfilter, ss) == RTNORM)
{
acutRelRb(ssfilter);
if (acedSSName(ss, 0, ename) != RTNORM) return;
acedSSFree(ss);
AcDbObjectId objid;
if (acdbGetObjectId(objid, ename) != Acad::eOk) return;
AcDbObjectPointer<AcDb3dSolid> pSolid(objid, AcDb::kForRead);
if (pSolid.openStatus() != Acad::eOk) return;
map<double, AcGePoint3d> pMap;
map<double, AcGePoint3d>::const_iterator it;
AcBrBrep brep;
brep.set(*(pSolid.object()));
AcBrBrepFaceTraverser acbrFaces;
for (acbrFaces.setBrep(brep); !acbrFaces.done(); acbrFaces.next())
{
AcBrFaceLoopTraverser acbrFaceLoop;
AcBrFace acbrFace;
acbrFaces.getFace(acbrFace);
for (acbrFaceLoop.setFace(acbrFace); !acbrFaceLoop.done(); acbrFaceLoop.next())
{
AcGeSurface* pSurface;
if (acbrFace.getSurface(pSurface) == AcBr::eOk)
{
AcGePoint3d pnt = pSurface->closestPointTo(pt);
delete pSurface;
double d = AcGeVector3d(pnt.asVector() - pt.asVector()).length();
pMap.insert(make_pair(d, pnt));
}
}
}
if (!pMap.empty())
{
std::pair<double, AcGePoint3d> minData = *min_element(pMap.begin(), pMap.end(), compare);
AcGePoint3d rpt = minData.second;
acutPrintf(_T("\nClosest distance: %.3f \n"), minData.first);
AcDbPoint *pPoint = NULL;
pPoint = new AcDbPoint(rpt);
AcDbBlockTableRecordPointer pBTR(acdbCurDwg()->currentSpaceId(), AcDb::kForWrite);
if (pPoint && (pBTR.openStatus() == Acad::eOk))
{
pBTR->appendAcDbEntity(pPoint);
pPoint->close();
}
pPoint = new AcDbPoint(pt);
if (pPoint && (pBTR.openStatus() == Acad::eOk))
{
pBTR->appendAcDbEntity(pPoint);
pPoint->close();
}
}
}
}

The above will return the minimum distance from any point selected to the 3d solid - and can be easily changed to be called as a function from autolisp as extension (like passing a vector of 3d solids for now it is just one and loop over them, etc.) - will leave that out since not that many want to download a binary file.

Quote
Command: test
Point to test:
Select solid:
Closest distance: 4.055

HTH.-
« Last Edit: August 20, 2011, 09:53:53 PM by DeVo »

ribarm

  • Water Moccasin
  • Posts: 2126
  • Marko Ribar, architect
Re: height of lowest surface in 3dsolid?
« Reply #7 on: August 21, 2011, 05:16:43 AM »
I've modified code above, check it now...

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

:)

M.R. on Youtube

LE3

  • Guest
Re: height of lowest surface in 3dsolid?
« Reply #8 on: August 21, 2011, 12:08:18 PM »
I've modified code above, check it now...

M.R.

If you get a chance test the routine with the attached drawing save as 2010.

ribarm

  • Water Moccasin
  • Posts: 2126
  • Marko Ribar, architect
Re: height of lowest surface in 3dsolid?
« Reply #9 on: August 21, 2011, 04:48:46 PM »
You didn't correctly setup your UCS, but nevertheless it is supposed to work with all possible UCS systems... Change UCS to WCS and test for yourself. It works fine on my comp...

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

:)

M.R. on Youtube

LE3

  • Guest
Re: height of lowest surface in 3dsolid?
« Reply #10 on: August 21, 2011, 04:54:41 PM »
You didn't correctly setup your UCS, but nevertheless it is supposed to work with all possible UCS systems... Change UCS to WCS and test for yourself. It works fine on my comp...

M.R.

I did that on purpose - I know what you just pointed above.

ribarm

  • Water Moccasin
  • Posts: 2126
  • Marko Ribar, architect
Re: height of lowest surface in 3dsolid?
« Reply #11 on: August 22, 2011, 02:29:06 AM »
Well Devo, if you didn't know, routine measures distance from UCS origin point - '( 0 0 0 ) to lowest surface of object along axis parallel to relative UCS Z axis, so every time you want to check if surface is higher or lower it's good to know what distances are measured with your current UCS orientation and position...

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

:)

M.R. on Youtube

LE3

  • Guest
Re: height of lowest surface in 3dsolid?
« Reply #12 on: August 22, 2011, 12:17:52 PM »
Well Devo, if you didn't know, routine measures distance from UCS origin point - '( 0 0 0 ) to lowest surface of object along axis parallel to relative UCS Z axis, so every time you want to check if surface is higher or lower it's good to know what distances are measured with your current UCS orientation and position...

M.R.

If you read my post on Reply #5 - was trying to make my/a point - about alisp/vlisp - that's all.

ribarm

  • Water Moccasin
  • Posts: 2126
  • Marko Ribar, architect
Re: height of lowest surface in 3dsolid?
« Reply #13 on: August 23, 2011, 06:49:12 AM »
Here, this should do it, but something is wrong... CAD doesn't find result of computation... Anyway, here is code, so if someone can fix it, go ahead and take all the thanks...

Code: [Select]
;; TRP
;; Transposes a matrix -Doug Wilson-
;;
;; Argument : a matrix

(defun trp (m) (apply 'mapcar (cons 'list m)))

;; MXV
;; Applies a transformation matrix to a vector -Vladimir Nesterovsky-
;;
;; Arguments : a matrix and a vector

(defun mxv (m v)
  (mapcar (function (lambda (r) (apply '+ (mapcar '* r v)))) m)
)

;; MXM
;; Multiplies (combinates) two matrices -Vladimir Nesterovsky-
;;
;; Arguments : two matrices

(defun mxm (m q)
  (mapcar (function (lambda (r) (mxv (trp q) r))) m)
)

(defun c:npt3DS nil (c:nearestpointto3DSolid))
(defun c:nearestpointto3DSolid ( / aobj adoc mspc pt radpt rad obj1 obj11 obj2 obj22 obj3 k matrix scf matrixn 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)
  (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 matrix
      (list
        (list 1.0001 0. 0. (car pt))
        (list 0. 1.0001 0. (cadr pt))
        (list 0. 0. 1.0001 (caddr pt))
        (list 0. 0. 0. 1.)
      )
    )
;    (if (= k 1) (setq matirixn matrix))
;    (setq matrixn (mxm matrix matrixn))
    (vla-transformby obj1
      (vlax-tmatrix matrix)
    )
    (vla-update obj1)
  )
  (setq scf (expt 1.0001 k))
  (setq matrixn
    (list
      (list scf 0. 0. (car pt))
      (list 0. scf 0. (cadr pt))
      (list 0. 0. scf (caddr pt))
      (list 0. 0. 0. 1.)
    )
  )
  (setq obj1
    (vla-addSphere mspc (vlax-3d-point pt) rad)
  )
  (setq obj11
    (vla-transformby obj1
      (vlax-tmatrix matrixn)
    )
  )
  (vla-copy obj22)
  (setq obj3
    (vla-update
      (vla-Boolean obj11 acintersection obj22)
    )
  )
  (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)

M.R.
« Last Edit: August 25, 2011, 05:56:21 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2126
  • Marko Ribar, architect
Re: height of lowest surface in 3dsolid?
« Reply #14 on: August 23, 2011, 09:07:43 AM »
Now it works... Without using matrices and transformations of objects... Only use of vl-cmdf commands :

Code: [Select]
(defun c:npt3DS nil (c:nearestpointto3DSolid))
(defun c:nearestpointto3DSolid ( / aobj adoc mspc pt radpt rad obj1 obj1e obj11 obj2 obj22 obj3 k scf 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)
  (setq obj22 (vla-copy obj2))
  (vla-copy obj22)
  (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 1.001)
  )
  (setq scf (expt 1.001 k))
  (setq obj1
    (vla-addSphere mspc (vlax-3d-point pt) rad)
  )
  (setq obj1e (vlax-vla-object->ename obj1))
  (vl-cmdf "_.scale" obj1e "" pt scf)
  (setq obj11 (vlax-ename->vla-object obj1e))
  (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)
      )
    )
  )
  (entdel (entlast))
  (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)

M.R. :lol:
« Last Edit: August 25, 2011, 05:59:00 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2126
  • 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: 2126
  • 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: 2126
  • 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