### Author Topic: Recreate path curve...  (Read 720 times)

0 Members and 1 Guest are viewing this topic.

#### ribarm

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

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)

#### ribarm

• Water Moccasin
• Posts: 2101
• 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.     (or
64.       (not (setq arraypth (car (entsel "\nPick ARRAYPATH BLOCK..."))))
65.       (if arraypth
66.         (or
67.           (/= (cdr (assoc 0 (entget arraypth))) "INSERT")
68.           (not (wcmatch (cdr (assoc 2 (entget arraypth))) "`*U*"))
69.         )
70.       )
71.     )
72.     (prompt "\nMissed or picked wrong entity type...")
73.   )
74.   (initget 6)
75.   (setq n (getint "\nSpecify density of array - precision of curve recreation <25> : "))
76.   (if (null n)
77.     (setq n 25)
78.   )
79.   (setq on (getpropertyvalue arraypth "Items"))
80.   (setq ospc (getpropertyvalue arraypth "ItemSpacing"))
81.   (setq met (getpropertyvalue arraypth "Method"))
82.   (vl-cmdf "_.ARRAYEDIT" arraypth "_M" "_D" "_I" n)
83.   (while (< 0 (getvar 'cmdactive))
84.     (vl-cmdf "")
85.   )
86.   (setq e (tblobjname "BLOCK" (cdr (assoc 2 (entget arraypth)))))
87.   (while (setq e (entnext e))
88.     (setq ip (cadr (refgeom e)))
89.     (setq p (apply '(lambda ( mat vec ) (mapcar '+ (mxv mat ip) vec)) (refgeom arraypth)))
90.     (setq pl (cons p pl))
91.   )
92.   (setq pl (reverse pl))
93.   (vl-cmdf "_.SPLINE")
94.   (foreach p pl
95.     (vl-cmdf "_non" (trans p 0 1))
96.   )
97.   (while (< 0 (getvar 'cmdactive))
98.     (vl-cmdf "")
99.   )
100.   (if (= met 0)
101.     (vl-cmdf "_.ARRAYEDIT" arraypth "_M" "_D" "_I" on)
102.     (vl-cmdf "_.ARRAYEDIT" arraypth "_M" "_M" "_I" on ospc)
103.   )
104.   (while (< 0 (getvar 'cmdactive))
105.     (vl-cmdf "")
106.   )
107.   (princ)
108. )
109.

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)

#### roy_043

• Water Moccasin
• Posts: 1700
##### 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: 1848
##### 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

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

#### ribarm

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

#### ribarm

• Water Moccasin
• Posts: 2101
• 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.       (vl-remove nil
22.         (list
23.           '(0 . "LWPOLYLINE")
24.           '(100 . "AcDbEntity")
25.           (assoc 67 dxf_ent)
26.           (assoc 410 dxf_ent)
27.           (assoc 8 dxf_ent)
28.           (if (assoc 6 dxf_ent) (assoc 6 dxf_ent) '(6 . "BYLAYER"))
29.           (if (assoc 62 dxf_ent) (assoc 62 dxf_ent) '(62 . 256))
30.           (if (assoc 420 dxf_ent) (assoc 420 dxf_ent))
31.           (if (assoc 370 dxf_ent) (assoc 370 dxf_ent) '(370 . -3))
32.           (if (assoc 48 dxf_ent) (assoc 48 dxf_ent) '(48 . 1.0))
33.           '(100 . "AcDbPolyline")
34.           '(90 . 2)
35.           '(70 . 1)
36.           (cons 43 (getvar "PLINEWID"))
38.           (if (assoc 39 dxf_ent) (assoc 39 dxf_ent) '(39 . 0.0))
39.           (cons 10 (list (car fst_pt) (cadr fst_pt)))
40.           '(40 . 0.0)
41.           '(41 . 0.0)
42.           '(42 . 1.0)
43.           (cons 10 (list (car opp_pt) (cadr opp_pt)))
44.           '(40 . 0.0)
45.           '(41 . 0.0)
46.           '(42 . 1.0)
47.           (assoc 210 dxf_ent)
48.         )
49.       )
50.     )
51.     (entdel ent)
52.   )
53.   (princ)
54. )
55.
56. (defun c:lwc ( / cmd ent dxf_ent pt_cen radius fst_pt opp_pt new_ep )
57.   (setq cmd (getvar 'cmdecho))
58.   (setvar 'cmdecho 1)
59.   (vl-cmdf "_.CIRCLE")
60.   (while (> (getvar 'cmdactive) 0) (vl-cmdf "\\"))
61.   (setq
62.     ent (entlast)
63.     dxf_ent (entget ent)
64.     pt_cen (cdr (assoc 10 dxf_ent))
65.     radius (cdr (assoc 40 dxf_ent))
66.     fst_pt (polar pt_cen 0.0 radius)
67.     opp_pt (polar pt_cen pi radius)
68.   )
69.     (vl-remove nil
70.       (list
71.         '(0 . "LWPOLYLINE")
72.         '(100 . "AcDbEntity")
73.         (assoc 67 dxf_ent)
74.         (assoc 410 dxf_ent)
75.         (assoc 8 dxf_ent)
76.         (if (assoc 6 dxf_ent) (assoc 6 dxf_ent) '(6 . "BYLAYER"))
77.         (if (assoc 62 dxf_ent) (assoc 62 dxf_ent) '(62 . 256))
78.         (if (assoc 420 dxf_ent) (assoc 420 dxf_ent))
79.         (if (assoc 370 dxf_ent) (assoc 370 dxf_ent) '(370 . -3))
80.         (if (assoc 48 dxf_ent) (assoc 48 dxf_ent) '(48 . 1.0))
81.         '(100 . "AcDbPolyline")
82.         '(90 . 2)
83.         '(70 . 1)
84.         (cons 43 (getvar "PLINEWID"))
86.         (if (assoc 39 dxf_ent) (assoc 39 dxf_ent) '(39 . 0.0))
87.         (cons 10 (list (car fst_pt) (cadr fst_pt)))
88.         '(40 . 0.0)
89.         '(41 . 0.0)
90.         '(42 . 1.0)
91.         (cons 10 (list (car opp_pt) (cadr opp_pt)))
92.         '(40 . 0.0)
93.         '(41 . 0.0)
94.         '(42 . 1.0)
95.         (assoc 210 dxf_ent)
96.       )
97.     )
98.   )
99.   (entdel ent)
100.   (setvar 'cmdecho cmd)
101.   (princ)
102. )
103.

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)