Message 1 of 10
Making a square to circle duct transition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Currently I have a function in which the elevation (height or z coordinate) of polyline (square most of the time) and circle are compared and if they are in same elevation than gives error, and if not it runs a program called CONNVERTI.
- In function CONNVERTI it ask user to select a circle and a polyline. After that it sets the number of segments circle will be divided into (which is 20).
- A math calculation is set to start making points on circle with the increasing angle (from 0° to 360° so that it make points equal to number segments it has been set to).
- After that connect two vertices of polyline to nearest quadrant (same with the other 3 quadrants connecting to nearest two vertices of polyline, and making a closed 3dpolyline surface will be make extrusion and it will not extrude if it's not a made with closed surface with single line).
- The points which lies between two quadrants will be connect to the nearest vertex (same making closed surface single 3dpolyline).
- Once all surfaces are created the than just extrude all surface with 1/4 inch thickness.
The code I did is:(defun c:S2CTRANS ()(setq circle (car (entsel "\nSelect a circle : "))) ; Select a circle(setq polyline (car (entsel "\nSelect a polyline: "))) ; Select a polyline(setq dxf-data1 (entget circle)) ; Get the DXF data of the circle(setq dxf-data2 (entget polyline)) ; Get the DXF data of the polyline(setq circleElevation (cdr (assoc 10 dxf-data1))) ; Extract the circle elevation(setq polylineElevation (cdr (assoc 38 dxf-data2))) ; Extract the polyline elevation(setq z1 (rtos (caddr circleElevation)))(setq z2 (rtos polylineElevation))(if (= z1 z2)(alert "\nObjects have the same Elevation.\n")(PROGN(prompt "\nObjects have different Elevation.\n")(C:CONNVERTI)))(princ))(defun CONNVERTI ()(setq polyline (car (entsel "\nSelect a polyline: "))) ; Select a polyline(setq circle (car (entsel "\nSelect a circle: "))) ; Select a circle(setq dxf-data (entget circle)) ; Get the DXF data of the circle(setq circleData (cdr (assoc 10 dxf-data))) ; Extract elevation value(setq radius (cdr (assoc 40 dxf-data))) ; Extract radius(setq center (list (nth 0 circleData) (nth 1 circleData)))(setq ele (nth 2 circleData))(setq numSegments 20) ; number of segments circle will be divided into.(setq angleIncrement (/ (* 2.0 pi) numSegments)) ; Calculate the angle increment(setq angle 0.0) ; Initialize the angle; Create a list to store the 3D polyline points(setq polylinePoints '()); ; ; Create segments by specifying the end points on the circle(repeat numSegments(setq x (cos angle))(setq y (sin angle))(setq endPoint (list (+ (car center) (* radius x))(+ (cadr center) (* radius y)))) ; Calculate the endpoint(setq xP (car endPoint))(setq yP (cadr endPoint))(setq point-entity (entmake (list '(0 . "POINT")(cons 10 (list xP yP ele))(cons 8 "Layer1") ; Replace with your desired layer)))(setq polylinePoints (cons endPoint polylinePoints))(setq angle (+ angle angleIncrement)) ; Update the angle for the next segment); (setq particularPoint (car polylinePoints)); (princ particularPoint); (setq xP (car particularPoint)); (setq yP (cadr particularPoint)); (setq point-entity (entmake (list '(0 . "POINT"); (cons 10 (list xP yP ele)); (cons 8 "Layer1") ; Replace with your desired layer; )))(if (= polylineVertices numPoints)(progn(setq i 0)(repeat polylineVertices(setq pt1 (vlax-curve-getPointAtDist polyline i))(setq pt2 (nth i polylinePoints))(setq polylineToCirclePoints (cons pt1 polylineToCirclePoints))(setq polylineToCirclePoints (cons pt2 polylineToCirclePoints))(setq i (+ i 1))))(progn(princ "The number of polyline vertices does not match the number of circle points.")(exit))); Create the 3D polyline(setq polyline3D (vlax-invoke (vla-get-activedocument (vlax-get-acad-object)) 'Add3DPoly polylineToCirclePoints))(princ (strcat "Created a 3D polyline connecting the circle to the polyline."))(princ))
Thanks,