Author Topic: cube with vla-Add3DMesh  (Read 2204 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 725
cube with vla-Add3DMesh
« on: May 04, 2023, 06:23:51 AM »
I want create a cube with vla-Add3DMesh

I don't understand the ORDER of POINTS

And obviously something goes wrong

Can somebody help me ?

( and what about vla-AddPolyfaceMesh ? )

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun :PT-SET-Z (ptx z) (list (car ptx)(cadr ptx) z) )
  3.  
  4. (defun C:CUBE-MESH ( / p10 p1z p20 p2z p30 p3z p40 p4z pi/2 )
  5.    (setq pi/2 (/ pi 2.0) )
  6.  
  7.    (setq p10 (getpoint "\nbase point :") )
  8.    (setq p20 (polar p10 0.0  1.0) )
  9.    (setq p30 (polar p20 pi/2 1.0) )
  10.    (setq p40 (polar p10 pi/2 1.0) )
  11.  
  12.    (setq p1z (:PT-SET-Z P10 1.0) )
  13.    (setq p2z (polar p1z 0.0  1.0) )
  14.    (setq p3z (polar p2z pi/2 1.0) )
  15.    (setq p4Z (polar p1z pi/2 1.0) )
  16.    
  17.    (:3D-ADD-MESH (list p10 p20 p30 p40 p1z p2z p3z p4z) )
  18. )
  19.  
  20.  
  21. (defun :3D-ADD-MESH (point-lst / acadobj doc meshobj modelspace msize nsize points )
  22.    
  23.    (setq acadObj (vlax-get-acad-object)  
  24.          doc (vla-get-ActiveDocument acadObj )
  25.    )
  26.    (setq point-lst (apply 'append point-lst) )
  27.    (setq points (vlax-make-safearray vlax-vbDouble (cons 0 (- (length point-lst) 1) ) ) )  
  28.    (vlax-safearray-fill points point-lst )
  29.    (setq mSize 4 nSize 4)
  30.    (setq modelSpace (vla-get-ModelSpace doc) )  
  31.    (setq meshObj (vla-Add3DMesh modelSpace mSize nSize points) )
  32.  
  33. )
  34.  
  35.  
  36. (defun C:CM () (C:CUBE-MESH) )
  37.  

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: cube with vla-Add3DMesh
« Reply #1 on: May 04, 2023, 08:07:29 AM »
Correct this line :
(setq p1z (:PT-SET-Z P10 1.0) )

Your a=1.0, so :
(setq p1z (list (car P10) (cadr P10) 1.0))
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: cube with vla-Add3DMesh
« Reply #2 on: May 04, 2023, 08:29:33 AM »
Ribarm, sorry,
but I don't understand !

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: cube with vla-Add3DMesh
« Reply #3 on: May 04, 2023, 08:44:27 AM »
Ribarm, sorry,
but I don't understand !

Your line 12 is wrong...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: cube with vla-Add3DMesh
« Reply #4 on: May 04, 2023, 08:46:01 AM »
Ribarm, sorry,
but I don't understand !

Your line 12 is wrong...

Oh sorry, I saw it... No it's not wrong...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: cube with vla-Add3DMesh
« Reply #5 on: May 04, 2023, 09:01:07 AM »
Everything is OK, you just missed to put :vlax-true to Nclose and Mclose...

Here is revision that should work good-excellent...

Code - Auto/Visual Lisp: [Select]
  1. (defun :PT-SET-Z (ptx z) (list (car ptx)(cadr ptx) z) )
  2.  
  3. (defun C:CUBE-MESH ( / p10 p1z p20 p2z p30 p3z p40 p4z pi/2 )
  4.  
  5.    (setq pi/2 (/ pi 2.0) )
  6.  
  7.    (setq p10 (getpoint "\nbase point :") )
  8.    (setq p20 (polar p10 0.0  1.0) )
  9.    (setq p30 (polar p20 pi/2 1.0) )
  10.    (setq p40 (polar p10 pi/2 1.0) )
  11.  
  12.    (setq p1z (:PT-SET-Z P10 1.0) )
  13.    (setq p2z (polar p1z 0.0  1.0) )
  14.    (setq p3z (polar p2z pi/2 1.0) )
  15.    (setq p4Z (polar p1z pi/2 1.0) )
  16.  
  17.    (:3D-ADD-MESH (list p10 p20 p30 p40 p1z p2z p3z p4z) )
  18. )
  19.  
  20. (defun :3D-ADD-MESH (point-lst / acadobj doc meshobj modelspace msize nsize points )
  21.    (setq acadObj (vlax-get-acad-object)  
  22.          doc (vla-get-ActiveDocument acadObj )
  23.    )
  24.    (setq point-lst (apply 'append point-lst) )
  25.    (setq points (vlax-make-safearray vlax-vbDouble (cons 0 (- (length point-lst) 1) ) ) )  
  26.    (vlax-safearray-fill points point-lst )
  27.    (setq mSize 4 nSize 4)
  28.    (setq modelSpace (vla-get-ModelSpace doc) )  
  29.    (setq meshObj (vla-Add3DMesh modelSpace mSize nSize points) )
  30.    (vla-put-nclose meshObj :vlax-true )
  31.    (vla-put-mclose meshObj :vlax-true )
  32.    (princ)
  33. )
  34.  
  35. (defun C:CM () (C:CUBE-MESH) )
  36.  

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

:)

M.R. on Youtube

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: cube with vla-Add3DMesh
« Reply #6 on: May 04, 2023, 09:57:47 AM »
no, it goes wrong !

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: cube with vla-Add3DMesh
« Reply #7 on: May 04, 2023, 10:08:58 AM »
What CAD are you using?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: cube with vla-Add3DMesh
« Reply #8 on: May 04, 2023, 10:18:22 AM »
Here is my PNG...
Using BricsCAD V23...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: cube with vla-Add3DMesh
« Reply #9 on: May 04, 2023, 10:23:43 AM »
Here is my PNG, using ACAD 2024 and ACAD 2022...

So, something's wrong with ACAD - bug...
« Last Edit: May 04, 2023, 10:26:50 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: cube with vla-Add3DMesh
« Reply #10 on: May 04, 2023, 10:34:36 AM »
Ribarm,
acad 2022

however the BricsCAD image also represents a cube without the upper and the lower face . . .

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: cube with vla-Add3DMesh
« Reply #11 on: May 04, 2023, 11:04:22 AM »
I've tried plane by plane - by entmake... But no avail in ACAD... In ACAD is that with 0,0,0 point and in BricsCAD there is nothing - neither error, nor output :

Code - Auto/Visual Lisp: [Select]
  1. (defun :PT-SET-Z (ptx z) (list (car ptx)(cadr ptx) z) )
  2.  
  3. (defun C:CUBE-MESH ( / p10 p1z p20 p2z p30 p3z p40 p4z pi/2 mplane pmsh )
  4.  
  5.    (setq pi/2 (/ pi 2.0) )
  6.  
  7.    (setq p10 (getpoint "\nbase point :") )
  8.    (setq p20 (polar p10 0.0  1.0) )
  9.    (setq p30 (polar p20 pi/2 1.0) )
  10.    (setq p40 (polar p10 pi/2 1.0) )
  11.  
  12.    (setq p1z (:PT-SET-Z P10 1.0) )
  13.    (setq p2z (polar p1z 0.0  1.0) )
  14.    (setq p3z (polar p2z pi/2 1.0) )
  15.    (setq p4Z (polar p1z pi/2 1.0) )
  16.  
  17.    ;(:3D-ADD-MESH (list p10 p20 p30 p40 p1z p2z p3z p4z) )
  18.    (defun mplane ( p1 p2 p3 p4 )
  19.       (setq pmsh (entmakex (list '(0 . "POLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolygonMesh") '(66 . 1) '(10 0.0 0.0 0.0) '(70 . 16) '(40 . 0.0) '(41 . 0.0) '(210 0.0 0.0 1.0) (cons 71 4) (cons 72 4) '(73 . 0) '(74 . 0) '(75 . 0))))
  20.       (foreach p (list p1 p2 p3 p4)
  21.         (entmake (list '(0 . "VERTEX") '(100 . "AcDbEntity") '(100 . "AcDbVertex") '(100 . "AcDbPolygonMeshVertex") (cons 10 p) '(40 . 0.0) '(41 . 0.0) '(42 . 0.0) '(70 . 64) '(50 . 0.0) '(71 . 0) '(72 . 0) '(73 . 0) '(74 . 0)))
  22.       )
  23.       (entmake (list '(0 . "SEQEND") '(100 . "AcDbEntity") (cons -2 pmsh)))
  24.    )
  25.  
  26.    (mplane p10 p20 p2z p1z)
  27.    (vla-put-nclose (vlax-ename->vla-object (entlast)) :vlax-true)
  28.    (vla-put-mclose (vlax-ename->vla-object (entlast)) :vlax-true)
  29.    (mplane p20 p30 p3z p2z)
  30.    (vla-put-nclose (vlax-ename->vla-object (entlast)) :vlax-true)
  31.    (vla-put-mclose (vlax-ename->vla-object (entlast)) :vlax-true)
  32.    (mplane p30 p40 p4z p3z)
  33.    (vla-put-nclose (vlax-ename->vla-object (entlast)) :vlax-true)
  34.    (vla-put-mclose (vlax-ename->vla-object (entlast)) :vlax-true)
  35.    (mplane p40 p10 p4z p1z)
  36.    (vla-put-nclose (vlax-ename->vla-object (entlast)) :vlax-true)
  37.    (vla-put-mclose (vlax-ename->vla-object (entlast)) :vlax-true)
  38.    (mplane p10 p20 p30 p40)
  39.    (vla-put-nclose (vlax-ename->vla-object (entlast)) :vlax-true)
  40.    (vla-put-mclose (vlax-ename->vla-object (entlast)) :vlax-true)
  41.    (mplane p1z p2z p3z p4z)
  42.    (vla-put-nclose (vlax-ename->vla-object (entlast)) :vlax-true)
  43.    (vla-put-mclose (vlax-ename->vla-object (entlast)) :vlax-true)
  44.    (princ)
  45. )
  46.  
  47. (defun :3D-ADD-MESH (point-lst / acadobj doc meshobj modelspace msize nsize points )
  48.    (setq acadObj (vlax-get-acad-object)  
  49.          doc (vla-get-ActiveDocument acadObj )
  50.    )
  51.    (setq point-lst (apply 'append point-lst) )
  52.    (setq points (vlax-make-safearray vlax-vbDouble (cons 0 (- (length point-lst) 1) ) ) )  
  53.    (vlax-safearray-fill points point-lst )
  54.    (setq mSize 4 nSize 4)
  55.    (setq modelSpace (vla-get-ModelSpace doc) )  
  56.    (setq meshObj (vla-Add3DMesh modelSpace mSize nSize points) )
  57.    (vla-put-nclose meshObj :vlax-true )
  58.    (vla-put-mclose meshObj :vlax-true )
  59.    (princ)
  60. )
  61.  
  62. (defun C:CM () (C:CUBE-MESH) )
  63.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: cube with vla-Add3DMesh
« Reply #12 on: May 04, 2023, 11:28:25 AM »
I've tried also with Polyface Mesh, but it's a bug in AutoCAD - that with 0,0,0 point and in BricsCAD no output...

Code - Auto/Visual Lisp: [Select]
  1. (defun :PT-SET-Z (ptx z) (list (car ptx)(cadr ptx) z) )
  2.  
  3. (defun C:CUBE-MESH ( / p10 p1z p20 p2z p30 p3z p40 p4z pi/2 draw_mesh )
  4.  
  5.    (setq pi/2 (/ pi 2.0) )
  6.  
  7.    (setq p10 (getpoint "\nbase point :") )
  8.    (setq p20 (polar p10 0.0  1.0) )
  9.    (setq p30 (polar p20 pi/2 1.0) )
  10.    (setq p40 (polar p10 pi/2 1.0) )
  11.  
  12.    (setq p1z (:PT-SET-Z P10 1.0) )
  13.    (setq p2z (polar p1z 0.0  1.0) )
  14.    (setq p3z (polar p2z pi/2 1.0) )
  15.    (setq p4Z (polar p1z pi/2 1.0) )
  16.  
  17.    ;(:3D-ADD-MESH (list p10 p20 p30 p40 p1z p2z p3z p4z) )
  18.  
  19.    (defun draw_mesh ( vlist mmesh nmesh mflg nflg / cflg )
  20.    (and (= (type vlist) 'LIST)
  21.    (= (type nmesh) 'INT)
  22.    (= (type mmesh) 'INT)
  23.    (< nmesh 256)
  24.    (< mmesh 256)
  25.    (> nmesh 2)
  26.    (> mmesh 2)
  27.    (cond ((and nflg mflg) (setq cflg 49))
  28.    (nflg (setq cflg 48))
  29.    (mflg (setq cflg 17))
  30.    (t (setq cflg 16)))
  31.    (entmake (list (cons 0 "POLYLINE")(cons 66 1)
  32.    (cons 10 (list 0 0 0))
  33.    (cons 70 cflg)
  34.    (cons 71 mmesh)(cons 72 nmesh)
  35.    (cons 39 0)))
  36.    (foreach v vlist
  37.    (entmake (list (cons 0 "VERTEX")
  38.    (cons 10 v)
  39.    (cons 70 64))))
  40.    (entmake (list (cons 0 "SEQEND")))))
  41.  
  42.    (draw_mesh (list p10 p20 p30 p40 p1z p1z p2z p3z p4z) 4 4 1 1)
  43.  
  44.    (princ)
  45. )
  46.  
  47. (defun :3D-ADD-MESH (point-lst / acadobj doc meshobj modelspace msize nsize points )
  48.    (setq acadObj (vlax-get-acad-object)  
  49.          doc (vla-get-ActiveDocument acadObj )
  50.    )
  51.    (setq point-lst (apply 'append point-lst) )
  52.    (setq points (vlax-make-safearray vlax-vbDouble (cons 0 (- (length point-lst) 1) ) ) )  
  53.    (vlax-safearray-fill points point-lst )
  54.    (setq mSize 4 nSize 4)
  55.    (setq modelSpace (vla-get-ModelSpace doc) )  
  56.    (setq meshObj (vla-Add3DMesh modelSpace mSize nSize points) )
  57.    (vla-put-nclose meshObj :vlax-true )
  58.    (vla-put-mclose meshObj :vlax-true )
  59.    (princ)
  60. )
  61.  
  62. (defun C:CM () (C:CUBE-MESH) )
  63.  

M.R.
« Last Edit: May 04, 2023, 12:31:58 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: cube with vla-Add3DMesh
« Reply #13 on: May 04, 2023, 12:36:23 PM »
@Domenico,

Those coding examples all fail, because I am not familiar with MESHES and creation other than Polygon Meshes for which I've posted in DOWNLOAD section of cadtutor.net EDGENET routines...
If you don't mind, lisp version of 3D command exist in BricsCAD and I suppose in AutoCAD too... When started "3D", you'll choose what do you need among which you can find BOX as entity MESH...

Good luck,
happy coding...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: cube with vla-Add3DMesh
« Reply #14 on: May 04, 2023, 12:59:05 PM »
Here you are :

Code - Auto/Visual Lisp: [Select]
  1. (defun :PT-SET-Z (ptx z) (list (car ptx)(cadr ptx) z) )
  2.  
  3. (defun C:CUBE-MESH ( / p10 p1z p20 p2z p30 p3z p40 p4z pi/2 pfmsh )
  4.  
  5.    (setq pi/2 (/ pi 2.0) )
  6.  
  7.    (setq p10 (getpoint "\nbase point :") )
  8.    (setq p20 (polar p10 0.0  1.0) )
  9.    (setq p30 (polar p20 pi/2 1.0) )
  10.    (setq p40 (polar p10 pi/2 1.0) )
  11.  
  12.    (setq p1z (:PT-SET-Z P10 1.0) )
  13.    (setq p2z (polar p1z 0.0  1.0) )
  14.    (setq p3z (polar p2z pi/2 1.0) )
  15.    (setq p4Z (polar p1z pi/2 1.0) )
  16.  
  17.    ;(:3D-ADD-MESH (list p10 p20 p30 p40 p1z p2z p3z p4z) )
  18.  
  19.    (setq pfmsh (entmakex '((0 . "POLYLINE") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (100 . "AcDbPolyFaceMesh") (66 . 1) (10 0.0 0.0 0.0) (70 . 64) (40 . 0.0) (41 . 0.0) (210 0.0 0.0 1.0) (71 . 8) (72 . 6) (73 . 0) (74 . 0) (75 . 0))))
  20.    (foreach v (list p10 p20 p30 p40 p1z p2z p3z p4z)
  21.      (entmake (list '(0 . "VERTEX") '(100 . "AcDbEntity") '(67 . 0) '(410 . "Model") '(100 . "AcDbVertex") '(100 . "AcDbPolyFaceMeshVertex") (cons 10 v) '(40 . 0.0) '(41 . 0.0) '(42 . 0.0) '(70 . 192) '(50 . 0.0) '(71 . 0) '(72 . 0) '(73 . 0) '(74 . 0)))
  22.    )
  23.    (entmake '((0 . "VERTEX") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (100 . "AcDbFaceRecord") (10 0.0 0.0 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (70 . 128) (50 . 0.0) (71 . 1) (72 . 4) (73 . 3) (74 . 2)))
  24.    (entmake '((0 . "VERTEX") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (100 . "AcDbFaceRecord") (10 0.0 0.0 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (70 . 128) (50 . 0.0) (71 . 5) (72 . 6) (73 . 7) (74 . 8)))
  25.    (entmake '((0 . "VERTEX") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (100 . "AcDbFaceRecord") (10 0.0 0.0 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (70 . 128) (50 . 0.0) (71 . 1) (72 . 2) (73 . 6) (74 . 5)))
  26.    (entmake '((0 . "VERTEX") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (100 . "AcDbFaceRecord") (10 0.0 0.0 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (70 . 128) (50 . 0.0) (71 . 4) (72 . 8) (73 . 7) (74 . 3)))
  27.    (entmake '((0 . "VERTEX") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (100 . "AcDbFaceRecord") (10 0.0 0.0 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (70 . 128) (50 . 0.0) (71 . 1) (72 . 5) (73 . 8) (74 . 4)))
  28.    (entmake '((0 . "VERTEX") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (100 . "AcDbFaceRecord") (10 0.0 0.0 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (70 . 128) (50 . 0.0) (71 . 2) (72 . 3) (73 . 7) (74 . 6)))
  29.    (entmake (list '(0 . "SEQEND") '(100 . "AcDbEntity") '(67 . 0) '(410 . "Model") (cons -2 pfmsh)))
  30.    (princ)
  31. )
  32.  
  33. (defun :3D-ADD-MESH (point-lst / acadobj doc meshobj modelspace msize nsize points )
  34.    (setq acadObj (vlax-get-acad-object)  
  35.          doc (vla-get-ActiveDocument acadObj )
  36.    )
  37.    (setq point-lst (apply 'append point-lst) )
  38.    (setq points (vlax-make-safearray vlax-vbDouble (cons 0 (- (length point-lst) 1) ) ) )  
  39.    (vlax-safearray-fill points point-lst )
  40.    (setq mSize 4 nSize 4)
  41.    (setq modelSpace (vla-get-ModelSpace doc) )  
  42.    (setq meshObj (vla-Add3DMesh modelSpace mSize nSize points) )
  43.    (vla-put-nclose meshObj :vlax-true )
  44.    (vla-put-mclose meshObj :vlax-true )
  45.    (princ)
  46. )
  47.  
  48. (defun C:CM () (C:CUBE-MESH) )
  49.  

I was inspecting DXF data after successful creation BOX from "3D" command... (entmake) should work both in AutoCAD and in BricsCAD...
HTH.
M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube