Author Topic: Recreate path curve...  (Read 3750 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Recreate path curve...
« on: October 28, 2018, 11:53:40 AM »
I want this to be discussed also here on this site :
https://www.cadtutor.net/forum/topic/66077-recreat-path-of-object-array-path/

Beside array-path object it's also important to consider sweeps or path extrusion 3D SOLIDS...

I am beginning to feel like this is put under the carpet...

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

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Recreate path curve...
« Reply #1 on: October 28, 2018, 08:20:17 PM »
I figured out for array path anonymous block...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:extractarraypathcurve ( / refgeom mxv mxm trp arraypth n on ospc met e ip p pl )
  2.  
  3.   ;; RefGeom (gile)
  4.   ;; Returns a list whose first item is a 3x3 transformation matrix and
  5.   ;; second item the object insertion point in its parent (xref, block or space)
  6.    
  7.   (defun refgeom ( ent / ang enx mat ocs )
  8.       (setq enx (entget ent)
  9.             ang (cdr (assoc 050 enx))
  10.             ocs (cdr (assoc 210 enx))
  11.       )
  12.       (list
  13.           (setq mat
  14.               (mxm
  15.                   (mapcar '(lambda ( v ) (trans v 0 ocs t))
  16.                      '(
  17.                           (1.0 0.0 0.0)
  18.                           (0.0 1.0 0.0)
  19.                           (0.0 0.0 1.0)
  20.                       )
  21.                   )
  22.                   (mxm
  23.                       (list
  24.                           (list (cos ang) (- (sin ang)) 0.0)
  25.                           (list (sin ang) (cos ang)     0.0)
  26.                          '(0.0 0.0 1.0)
  27.                       )
  28.                       (list
  29.                           (list (cdr (assoc 41 enx)) 0.0 0.0)
  30.                           (list 0.0 (cdr (assoc 42 enx)) 0.0)
  31.                           (list 0.0 0.0 (cdr (assoc 43 enx)))
  32.                       )
  33.                   )
  34.               )
  35.           )
  36.           (mapcar '- (trans (cdr (assoc 10 enx)) ocs 0)
  37.               (mxv mat (cdr (assoc 10 (tblsearch "block" (cdr (assoc 2 enx))))))
  38.           )
  39.       )
  40.   )
  41.  
  42.   ;; Matrix x Vector  -  Vladimir Nesterovsky
  43.   ;; Args: m - nxn matrix, v - vector in R^n
  44.    
  45.   (defun mxv ( m v )
  46.       (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
  47.   )
  48.    
  49.   ;; Matrix x Matrix  -  Vladimir Nesterovsky
  50.   ;; Args: m,n - nxn matrices
  51.    
  52.   (defun mxm ( m n )
  53.       ((lambda ( a ) (mapcar '(lambda ( r ) (mxv a r)) m)) (trp n))
  54.   )
  55.    
  56.   ;; Matrix Transpose  -  Doug Wilson
  57.   ;; Args: m - nxn matrix
  58.    
  59.   (defun trp ( m )
  60.       (apply 'mapcar (cons 'list m))
  61.   )
  62.  
  63.   (while
  64.     (or
  65.       (not (setq arraypth (car (entsel "\nPick ARRAYPATH BLOCK..."))))
  66.       (if arraypth
  67.         (or
  68.           (/= (cdr (assoc 0 (entget arraypth))) "INSERT")
  69.           (not (wcmatch (cdr (assoc 2 (entget arraypth))) "`*U*"))
  70.         )
  71.       )
  72.     )
  73.     (prompt "\nMissed or picked wrong entity type...")
  74.   )
  75.   (initget 6)
  76.   (setq n (getint "\nSpecify density of array - precision of curve recreation <25> : "))
  77.   (if (null n)
  78.     (setq n 25)
  79.   )
  80.   (setq on (getpropertyvalue arraypth "Items"))
  81.   (setq ospc (getpropertyvalue arraypth "ItemSpacing"))
  82.   (setq met (getpropertyvalue arraypth "Method"))
  83.   (vl-cmdf "_.ARRAYEDIT" arraypth "_M" "_D" "_I" n)
  84.   (while (< 0 (getvar 'cmdactive))
  85.     (vl-cmdf "")
  86.   )
  87.   (setq e (tblobjname "BLOCK" (cdr (assoc 2 (entget arraypth)))))
  88.   (while (setq e (entnext e))
  89.     (setq ip (cadr (refgeom e)))
  90.     (setq p (apply '(lambda ( mat vec ) (mapcar '+ (mxv mat ip) vec)) (refgeom arraypth)))
  91.     (setq pl (cons p pl))
  92.   )
  93.   (setq pl (reverse pl))
  94.   (vl-cmdf "_.SPLINE")
  95.   (foreach p pl
  96.     (vl-cmdf "_non" (trans p 0 1))
  97.   )
  98.   (while (< 0 (getvar 'cmdactive))
  99.     (vl-cmdf "")
  100.   )
  101.   (if (= met 0)
  102.     (vl-cmdf "_.ARRAYEDIT" arraypth "_M" "_D" "_I" on)
  103.     (vl-cmdf "_.ARRAYEDIT" arraypth "_M" "_M" "_I" on ospc)
  104.   )
  105.   (while (< 0 (getvar 'cmdactive))
  106.     (vl-cmdf "")
  107.   )
  108.   (princ)
  109. )
  110.  

Still remains for 3D SOLIDS - extrusions by path and sweeps... I can't figure out how to get centroids of regions that represent cross sections... I don't know how to generate cross sections basically...

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

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Recreate path curve...
« Reply #2 on: October 29, 2018, 04:04:33 AM »
I don't think it is possible to accurately recreate the path of a patharry. For example if the original path contains a small zig-zag between arrayed items.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Recreate path curve...
« Reply #3 on: October 29, 2018, 05:32:54 PM »
I have used SURFEXTRACTCURVE to find the path of a tube. But of course this has a very limited usage

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Recreate path curve...
« Reply #4 on: October 30, 2018, 07:21:54 AM »
I have used SURFEXTRACTCURVE to find the path of a tube. But of course this has a very limited usage

Sorry, but surfv isolines of surface don't exactly follow main central path curvature...
BTW. I've managed to do this with sweeps, but it's complicated, involves manual interventions; using DLL through NETLOAD; some short LSP files and it recreates the shape in manner I used in my above posted routine... Basically I get closed 3dpolyline cross sections which I then convert to regions and extrude them just 1e-3 to get centroids in WCS from reference extrusions, then add start/end points to point list of centroids - sweep was open so no starting/ending 3dpolylines cross sections - had to manually create them and get centroids which are appended to point list and finally SPLINE command - through all points... I've checked and I can clearly say that only this way is somewhat correct - copying SURFEXTRACTED curve in direction opposite to cross sections and placing it in start of sweep path is wrong...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Recreate path curve...
« Reply #5 on: October 30, 2018, 10:09:52 AM »
However Roy has the point... I think that it's important to recreated path be accurate... So my approaches are bad, but then again I don't know how to do it - extract exact curve directly from complex object... It seems that main data from curve is stored somewhere inside complex object... So if someone else has something different, let us know, please, if that's not confidential...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Recreate path curve...
« Reply #6 on: October 30, 2018, 06:50:50 PM »
Hi, I figured out how to get accurate path of sweeps and path extrusions... Firstly main shape must not be circle - you have to convert it to lwpolyline - also ellipse to pellipse (lwpolyline) - also spline to lwpolyline - with dense straight segments... Then you apply sweep or extrude by path of those shapes to any curve path... When 3DSOLID is generated, you remove path curve and then you experiment... Copy 3DSOLID some units away in X or Y directions and then zoom to experimental 3DSOLID... Then click on 3DSOLID and grips will show up - there are grips from shape-base and grip in the centroid of path which is imaginary - but grip exist... Then you click on one grip from shape until you overlap it with path grip and that's it... Now just do SOLIDEDIT -> Edge -> Copy edges and click all edges following path - one envelope edges of 3DSOLID must overlap path curve... Copy all touching path edges into X Y direction away on new location, then zoom to location - finally apply JOIN command and that's it path has been recreated... Now copy path back - reverse X Y direction 2 times distance and it should be exact copy of starting path curve... So it only is needed to convert circle to lwpolyline :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ci2lw ( / ss i ent dxf_ent pt_cen radius fst_pt opp_pt new_ep )
  2.   (princ "\nSelect a circles to be converted into a donuts - LWPOLYLINES...")
  3.   (while (null (setq ss (ssget "_:L" '((0 . "CIRCLE")))))
  4.     (princ "\nEmpty sel.set... Try again...")
  5.   )
  6.   (princ "\nThickness of donut <")
  7.   (princ (getvar "PLINEWID"))
  8.   (princ ">: ")
  9.   (initget 68)
  10.   (setq new_ep (getdist))
  11.   (if new_ep (setvar "PLINEWID" new_ep))
  12.   (repeat (setq i (sslength ss))
  13.     (setq
  14.       ent (ssname ss (setq i (1- i)))
  15.       dxf_ent (entget ent)
  16.       pt_cen (cdr (assoc 10 dxf_ent))
  17.       radius (cdr (assoc 40 dxf_ent))
  18.       fst_pt (polar pt_cen 0.0 radius)
  19.       opp_pt (polar pt_cen pi radius)
  20.     )
  21.     (entmake
  22.       (vl-remove nil
  23.         (list
  24.           '(0 . "LWPOLYLINE")
  25.           '(100 . "AcDbEntity")
  26.           (assoc 67 dxf_ent)
  27.           (assoc 410 dxf_ent)
  28.           (assoc 8 dxf_ent)
  29.           (if (assoc 6 dxf_ent) (assoc 6 dxf_ent) '(6 . "BYLAYER"))
  30.           (if (assoc 62 dxf_ent) (assoc 62 dxf_ent) '(62 . 256))
  31.           (if (assoc 420 dxf_ent) (assoc 420 dxf_ent))
  32.           (if (assoc 370 dxf_ent) (assoc 370 dxf_ent) '(370 . -3))
  33.           (if (assoc 48 dxf_ent) (assoc 48 dxf_ent) '(48 . 1.0))
  34.           '(100 . "AcDbPolyline")
  35.           '(90 . 2)
  36.           '(70 . 1)
  37.           (cons 43 (getvar "PLINEWID"))
  38.           (cons 38 (caddr pt_cen))
  39.           (if (assoc 39 dxf_ent) (assoc 39 dxf_ent) '(39 . 0.0))
  40.           (cons 10 (list (car fst_pt) (cadr fst_pt)))
  41.           '(40 . 0.0)
  42.           '(41 . 0.0)
  43.           '(42 . 1.0)
  44.           (cons 10 (list (car opp_pt) (cadr opp_pt)))
  45.           '(40 . 0.0)
  46.           '(41 . 0.0)
  47.           '(42 . 1.0)
  48.           (assoc 210 dxf_ent)
  49.         )
  50.       )
  51.     )
  52.     (entdel ent)
  53.   )
  54.   (princ)
  55. )
  56.  
  57. (defun c:lwc ( / cmd ent dxf_ent pt_cen radius fst_pt opp_pt new_ep )
  58.   (setq cmd (getvar 'cmdecho))
  59.   (setvar 'cmdecho 1)
  60.   (vl-cmdf "_.CIRCLE")
  61.   (while (> (getvar 'cmdactive) 0) (vl-cmdf "\\"))
  62.   (setq
  63.     ent (entlast)
  64.     dxf_ent (entget ent)
  65.     pt_cen (cdr (assoc 10 dxf_ent))
  66.     radius (cdr (assoc 40 dxf_ent))
  67.     fst_pt (polar pt_cen 0.0 radius)
  68.     opp_pt (polar pt_cen pi radius)
  69.   )
  70.     (vl-remove nil
  71.       (list
  72.         '(0 . "LWPOLYLINE")
  73.         '(100 . "AcDbEntity")
  74.         (assoc 67 dxf_ent)
  75.         (assoc 410 dxf_ent)
  76.         (assoc 8 dxf_ent)
  77.         (if (assoc 6 dxf_ent) (assoc 6 dxf_ent) '(6 . "BYLAYER"))
  78.         (if (assoc 62 dxf_ent) (assoc 62 dxf_ent) '(62 . 256))
  79.         (if (assoc 420 dxf_ent) (assoc 420 dxf_ent))
  80.         (if (assoc 370 dxf_ent) (assoc 370 dxf_ent) '(370 . -3))
  81.         (if (assoc 48 dxf_ent) (assoc 48 dxf_ent) '(48 . 1.0))
  82.         '(100 . "AcDbPolyline")
  83.         '(90 . 2)
  84.         '(70 . 1)
  85.         (cons 43 (getvar "PLINEWID"))
  86.         (cons 38 (caddr pt_cen))
  87.         (if (assoc 39 dxf_ent) (assoc 39 dxf_ent) '(39 . 0.0))
  88.         (cons 10 (list (car fst_pt) (cadr fst_pt)))
  89.         '(40 . 0.0)
  90.         '(41 . 0.0)
  91.         '(42 . 1.0)
  92.         (cons 10 (list (car opp_pt) (cadr opp_pt)))
  93.         '(40 . 0.0)
  94.         '(41 . 0.0)
  95.         '(42 . 1.0)
  96.         (assoc 210 dxf_ent)
  97.       )
  98.     )
  99.   )
  100.   (entdel ent)
  101.   (setvar 'cmdecho cmd)
  102.   (princ)
  103. )
  104.  

For ellipses - use PELLIPSE sys var and when set to 1 create pellipse with ELLIPSE command...

Now when you have polygonal shaped sweeps and path extrusions you don't need path - you can recreate it and use it for modifying existing 3DSOLID or create similar one with same path reference guide... Or array path, or, ... anything you wish...
Just remember for future - don't use circles or ellipses - you need stretchable shape for base entity...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Recreate path curve...
« Reply #7 on: October 31, 2018, 07:44:15 PM »
SURFEXTRACTCURVE does require you to find the median between the 2 curves of course.