Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/04/2023 in all areas

  1. See the link from MHUPP, or below, I needed the same a week or so ago so made this one: Poly2Chords will adjust the polyline to 'arcs' with straight sections, the Poly2Chords_List will return just the list of points and can be used in ssget with 'F' filter (needs a small change, Poly2Chords won't take acount of an arc with variable width) (defun c:Poly2Chords ( / MyEnt MyChords ModifiedEnt) ;;Select Entity (setq MyEnt (entget (car (entsel)))) ; Select Polyline / Line Entity (setq MyChords (getreal "Chords in 360 degrees: ")) (setq ModifiedEnt (PolyChords MyEnt MyChords)) ; Returns modified entity definition list (entmod ModifiedEnt) ; Here create a new polyline, can also (entmod...) instead (princ) ) (defun c:Poly2Chords_List ( / MyEnt MyChords ModifiedEnt) (defun mAssoc ( key lst / result ) ;;Lee Mac: https://www.cadtutor.net/forum/topic/27914-massoc-implementations/ (foreach x lst (if (= key (car x)) (setq result (cons (cdr x) result)) ) ) (setq MyEnt (entget (car (entsel)))) ; Select Polyline / Line Entity (setq MyChords (getreal "Chords in 360 degrees: ")) (setq ModifiedEnt (PolyChords MyEnt MyChords)) (princ (mAssoc 10 ModifiedEnt)) ) (defun PolyChords ( MyEnt vertexin360 / vertexin360 NewEnt acount p1 p2 open Open b MyBulge MyBulgeC StartAng EndAng MyRadius ccw Chordangle Chords ChordCount NewPt) (princ "OK ") ;;Add in start / end thickness 40, 41 ;;Add in if arc selected do conversion ;;;;; Sub Functions (defun LM:Bulge->Arc ( p1 p2 b / c r ) ;; Refer to Lee Mac Website ;;Gives Arc definition from pline Bulge (setq r (/ (* (distance p1 p2) (1+ (* b b))) 4 b) c (polar p1 (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b)))) r) ) (if (minusp b) (list c (angle c p2) (angle c p1) (abs r)) (list c (angle c p1) (angle c p2) (abs r)) ) ) (defun LM:BulgeCenter ( p1 p2 b ) ;; Refer to Lee Mac Website ;;Gives Arc definition from pline Bulge (polar p1 (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b)))) (/ (* (distance p1 p2) (1+ (* b b))) 4 b) ) ) (defun mAssoc ( key lst / result ) ;;Lee Mac: https://www.cadtutor.net/forum/topic/27914-massoc-implementations/ (foreach x lst (if (= key (car x)) (setq result (cons (cdr x) result)) ) ) (reverse result) ) ;;;;; End Sub Functions ;;Set Variables ;; (setq vertexin360 180) ; Number of chords in full circle, 360: every 1 degree (setq NewEnt (list)) ; New List for the modified entity definition (setq acount 0) ; A counter ;;Find curves '42' (while (< acount (length MyEnt)) (if (and (= (car (nth acount MyEnt)) 42) ; if dxf code 42 (/= (cdr (nth acount MyEnt)) 0) ; and is a value: a bulge! ) ; end and (progn (setq p1 (cdr (nth (- acount 3) MyEnt))) ; Start Coordinate (setq p2 (nth (+ acount 2) MyEnt)) ; End Coordinate as dxf code (if (= (car p2) 210) ; If P2 is "210" and not a "10" - end of polyline (if (= (cdr (assoc 70 MyEnt)) 1) (progn ; Closed Polyline (setq p2 (assoc 10 MyEnt)) ; Set end coordinate to start coordinate (setq open nil) ) ; end progn (progn ;Open PolyLine, end of polyline (setq Open "Open") ) ; end progn ) ; end if closed / open ) ; end if 210 (setq p2 (cdr p2)) ; End Coordinate (setq b (cdr (nth acount MyEnt))) ; Bulge (if (= Open "Open") ; If next point is '210' () ; End of chords (progn ; Calculate Chords (setq MyBulge (LM:Bulge->Arc p1 p2 b)) ; Bulge as arc (setq MyBulgeC (LM:BulgeCenter p1 p2 b) ) ; Bulge Centre (setq StartAng (nth 1 MyBulge)) ; start angle centre to point (setq EndAng (nth 2 MyBulge)) ; End angle centre to point (setq MyRadius (nth 3 MyBulge)) ; Bulge radius (if (< 0 b)(setq ccw 1)(setq ccw -1)) ; clockwise / anticlockwise (setq Chordangle (/ (* 4 (atan b))) ) (setq Chords (* ( / Chordangle (/ (* 2 pi) vertexin360)) ccw) ) ; point every nth degree ; (if (> Chords vertexin360) ;;Check number of chords isn't too big: TL, TR 'corners'. Not needed? ; (progn ; (setq Chordangle (+ (- (cadr MyBulge) (caddr MyBulge)) (* 1 pi)) ) ; (setq Chords (/ Chordangle (/ (* 2 pi) vertexin360) )) ; point every x degrees ; )) ; end progn ; end if (setq ChordCount 1) (while (< ChordCount Chords) (if (= ccw 1) (setq NewPt (polar MyBulgeC (+ (* (/ (* 2 pi) vertexin360) ChordCount) StartAng) MyRadius) ) (setq NewPt (polar MyBulgeC (- EndAng (* (/ (* 2 pi) vertexin360) ChordCount) ) MyRadius) ) ) (setq NewEnt (append NewEnt (list (cons 42 0)) ) ) ; bulge value: 0 (setq NewEnt (append NewEnt (list (cons 91 0)) ) ) ; Vertex Identifier (setq NewEnt (append NewEnt (list (cons 10 NewPt)) )) ; Point (setq NewEnt (append NewEnt (list (cons 40 0)) ) ) ; Start width (setq NewEnt (append NewEnt (list (cons 41 0)) ) ) ; end width (setq ChordCount (+ ChordCount 1)) ) ; end while ) ; end progn ) ; end if Open (end of line) ) ; end progn (progn (setq NewEnt (append NewEnt (list (nth acount MyEnt)) ) ) ; Add other DXF codes to NewEnt listing ) ; end progn ) ; end if '42' (setq acount (+ acount 1)) ) ; end while length MyEnt (setq NewEnt (subst (cons 90 (length (mAssoc 10 NewEnt))) (assoc 90 NewEnt) NewEnt )) ; update number of verticies ;;add in 70 for continuos line types NewEnt ; return new entity definition )
    1 point
  2. You should be able to get all the blocks using say SSGET "F" then check is the insertion point on the object. use maybe getclosestpointto it should reveal 0.0 for insert on pline use a (equal dist 0.0 1E-08) this looks for up to 0.000000001 offset. Sometimes its just not 0.0. Part 2 is break the arc down into little straights, so the "F" option works. Code is out there.
    1 point
  3. Pyautocad works, but its out of process so it’s very slow. However it’s good enough to tinker with Pyautocad uses ActiveX, which is powerful enough https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-A809CD71-4655-44E2-B674-1FE200B9FE30 You actually don’t need Pyautocad, you can generate early binding wrappers for AutoCAD using win32com’s makepy But Pyautocad has handy utilities, so it’s probably best to start with that
    1 point
  4. check out my project, Python for AutoCAD https://github.com/CEXT-Dan/PyRx wrapping Python around ARX. Python is pretty awesome with because of it's libraries. GIS stuff i.e. shapely / geopandas https://pyarx.blogspot.com/search/label/geopandas pandas is totally amazing for data extraction, I have a couple samples here https://pyarx.blogspot.com/2023/11/pandas-for-data-extraction-merging.html adding charts and doing data analysis https://pyarx.blogspot.com/2023/11/generate-plot-chart-from-autocad-table.html
    1 point
  5. Further to this, check your border template. I had grid dots showing in paper space with GRID set to off and a second set would show when I turned in on. My border template is a block and when I went into block editor GRID was set to on. When I set it to off, saved and went back to my drawing the extra set of dots (grid) was gone. Hope this helps as I have come across this before and just ignored it. Regards H.
    1 point
  6. Change dim style. Put in a defun that is loaded on startup. You should know how to do that. (command "._-dimstyle" "_restore" "DSTY") ; Set dimstyle current
    1 point
  7. Do you use a drawing template? With AutoCAD you can set all your options the way you want them before you even create a drawing. See this page. Once you have a drawing that is properly set up, remove the linework and save it as a template file (.DWT). Then you have two options. One option, if you use several types of drawings, is to create a library of templates. There is a default folder for templates, which you can locate in the Options window under Files | Template | Drawing Template File Location. Any time you create a new drawing, you're prompted to select a template, which you pick from this folder. Add your templates to that folder and you're good to go. The other option, if you have only one type, is to automatically create new drawings from your template. Under those same Template settings, there's an option for Default Template File Name for QNEW. That doesn't replace the default template, it just points to a different one. Make sure you save your template as a template, not as a drawing. That applies to new and revised templates.
    1 point
  8. 1 point
  9. Thanx Lee but cant see why i get an error in my test?
    1 point
×
×
  • Create New...