Recent Posts

Pages: [1] 2 3 ... 10
1
Now this function can only draw the 5MM center line in the rectangle
I hope to be able to draw a 5MM centerline with irregular graphic
Same function as this photo



Code: [Select]
(defun c:ss()
(setq cmd (getvar "cmdecho"))
(setq osm (getvar "osmode"))
(setvar "cmdecho" 0)
(command "undo" "be")
(If (progn
(princ "select:")
(setq ssa (ssget":S" '((0 . "lwpolyline") (90 . 4) (70 . 1))))
)
(progn
(setq dxf (entget (ssname ssa 0)))
(setq pts (mapcar 'cdr (vl-remove-if '(lambda(x)(/= (car x) 10)) dxf)))
(setq p1 (apply 'mapcar (cons 'min pts)))
(setq p3 (apply 'mapcar (cons 'max pts)))
(setq p2 (list (car p3) (cadr p1)))
(setq p4 (list (car p1) (cadr p3)))
(setq p14m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p1 p4))
(setq p14m2 (mapcar '+ p14m1 '(5 0)))
(setq p12m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p1 p2))
(setq p12m2 (mapcar '+ p12m1 '(0 5)))
(setq p23m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p2 p3))
(setq p23m2 (mapcar '+ p23m1 '(-5 0)))
(setq p34m1 (mapcar '(lambda(a b)(* 0.5 (+ a b))) p3 p4))
(setq p34m2 (mapcar '+ p34m1 '(0 -5)))
(setvar "osmode" 0)
(mapcar '(lambda(pts)
(command "_line" (car pts) (cadr pts) "" "_chprop" (entlast) "" "c" 1 "")
)
(list (list p14m1 p14m2)
(list p12m1 p12m2)
(list p23m1 p23m2)
(list p34m1 p34m2)
)
)
(mapcar '(lambda(pt dxy)
(setq pt1 (mapcar '+ pt dxy))
)
(list p1 p2 p3 p4 )
(list ' (-8 8) '(8 -8))   
)
)
)
(command "undo" "e")
(setvar "osmode" osm)
(setvar "cmdecho" cmd)
(princ)
)
2
.NET / Trouble implementing a similar function to trim
« Last post by themethodman on November 23, 2020, 07:20:46 PM »
For a single polyline entity of multiple segments, I'm looking to create a gap at each intersection. Ideally need to be able to specify the gap distance.

simple example:



more complex example:



Basic code outline:

1. Get polyline entity from editor
2. Explode polyline into individual polylines
3. test each polyline against each other for intersections (intersections must be 'genuine', eg. can't be between 2 consecutive segments)
4. create temporary circle at each intersection of specific radius
5. for each polyline, "trim" the contents inside the circle *(having difficulty at this point onwards)*, thereby removing the intersection
6. delete the temporary circles
7. for each existing polyline, where possible if they can be joined back up, do so

Biggest problem I'm facing is trimming each of the polylines at the circle intersections - I'm just not sure how to put this in code  :crazy2:

Eventually I would like to be able to incorporate arcs into the polylines.

My code so far (up to point 4):
 

Code: [Select]
        [CommandMethod("SelfIntersectPline")]

        public static void SelfIntersectPline()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptEntityOptions peo = new PromptEntityOptions(
                "\nSelect Curve: ");
            peo.SetRejectMessage("\nMust be a Curve...");

            PromptEntityResult per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK) return;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord ms = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                //get curve and explode into entities, store curves in entities dbobjectcollection
                Curve curve = per.ObjectId.GetObject(OpenMode.ForRead) as Curve;
                DBObjectCollection origDBObjects = new DBObjectCollection();
                curve.Explode(origDBObjects);

                //erase original curve
                var originalCurve = (Entity)tr.GetObject(curve.ObjectId, OpenMode.ForWrite);
                originalCurve.Erase();

                //create temp dbcollection for circle entities
                DBObjectCollection circleDBObjects = new DBObjectCollection();

                //convert exploded curve entities to polylines
                for (int i = origDBObjects.Count - 1; i >= 0; i--)
                {
                    Curve curveObj = origDBObjects[i] as Curve;
                    origDBObjects.Add(ConvertToPolyline(curveObj));
                    origDBObjects.RemoveAt(i);
                }

                //iterate through each polyline within entities collection
                for (int i = 0; i < origDBObjects.Count; ++i)
                {
                    for (int j = i + 1; j < origDBObjects.Count; ++j)
                    {
                        Polyline pl1 = origDBObjects[i] as Polyline;
                        Polyline pl2 = origDBObjects[j] as Polyline;
                        Point3dCollection points = new Point3dCollection();

                        //test for intersection(s)
                        pl1.IntersectWith(pl2, Intersect.OnBothOperands, points, IntPtr.Zero, IntPtr.Zero);

                        //validation for intersections
                        foreach (Point3d point in points)
                        {
                            // Skip the start/end points since they are connected vertices
                            if (point == pl1.StartPoint ||
                                point == pl1.EndPoint)
                            {
                                if (point == pl2.StartPoint ||
                                    point == pl2.EndPoint)
                                {
                                    // If two consecutive segments, then skip
                                    if (j == i + 1)
                                    {
                                        continue;
                                    }
                                }
                            }

                            //if genuine intersection detected, create temporary circle of specified radius at intersection
                            foreach (Point3d pt3d in points)
                            {
                                Circle c = new Circle();
                                c.Center = pt3d;
                                c.Radius = 0.5;
                                circleDBObjects.Add(c);
                            }
                        }
                    }
                }
3
AutoLISP (Vanilla / Visual) / Re: multi-leader style change ?
« Last post by ronjonp on November 23, 2020, 06:39:50 PM »
Glad to help :) .. you can also use an association list like so:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))))
  2.   ;;multi-leader
  3.   (progn (setq l '(("LDR_L100_RED" "LDR_L100") ("LDR_LS100_RED" "LDR_LS100")))
  4.          (repeat (setq int1 (sslength sel1))
  5.            (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  6.            (if (setq sn (cadr (assoc (strcase (vla-get-stylename obj1)) l)))
  7.              (vla-put-stylename obj1 sn)
  8.            )
  9.          )
  10.   )
  11. )

Or wcmatch if all *_RED names need to be changed:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))))
  2.   ;;multi-leader
  3.   (repeat (setq int1 (sslength sel1))
  4.     (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  5.     (if (wcmatch (setq sn (strcase (vla-get-stylename obj1))) "*_RED")
  6.       (vla-put-stylename obj1 (substr sn 1 (- (strlen sn) 4)))
  7.     )
  8.   )
  9. )
4
AutoLISP (Vanilla / Visual) / Re: multi-leader style change ?
« Last post by jlogan02 on November 23, 2020, 05:55:09 PM »
You could also combine the code like so:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))))
  2.   ;;multi-leader
  3.   (repeat (setq int1 (sslength sel1))
  4.     (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  5.     (setq sn (strcase (vla-get-stylename obj1)))
  6.     (cond ((= sn "LDR_L100_RED") (vla-put-stylename obj1 "LDR_L100"))
  7.      ((= sn "LDR_LS100_RED") (vla-put-stylename obj1 "LDR_LS100"))
  8.     )
  9.   )
  10. )


I figured there was a way shorter method. I did try (cond...but not like that.


Thanks for that, RonJonP.
5
AutoLISP (Vanilla / Visual) / Re: multi-leader style change ?
« Last post by ronjonp on November 23, 2020, 05:30:33 PM »
You could also combine the code like so:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))))
  2.   ;;multi-leader
  3.   (repeat (setq int1 (sslength sel1))
  4.     (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  5.     (setq sn (strcase (vla-get-stylename obj1)))
  6.     (cond ((= sn "LDR_L100_RED") (vla-put-stylename obj1 "LDR_L100"))
  7.           ((= sn "LDR_LS100_RED") (vla-put-stylename obj1 "LDR_LS100"))
  8.     )
  9.   )
  10. )
6
AutoLISP (Vanilla / Visual) / Re: multi-leader style change ?
« Last post by jlogan02 on November 23, 2020, 04:51:15 PM »
And once again...never mind, I found the error of my ways.

I'm clearly missing something here.

When I use these two routines as separate lisp routines, they work fine.

But if I place them together in the same lisp, both "RED" LDR's get changed to LDR_LS100.

Code - Auto/Visual Lisp: [Select]
  1.  (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))));;multi-leader
  2.    (repeat (setq int1 (sslength sel1))
  3.     (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  4.     (progn (eq (vla-get-stylename obj1) "LDR_L100_RED")
  5.        (vla-put-stylename obj1 "LDR_L100")
  6.        )
  7.      )
  8.    )
  9.  
  10.   (if (setq sel2 (ssget "_X" '((0 . "MULTILEADER"))));;multi-leader
  11.    (repeat (setq int2 (sslength sel2))
  12.     (setq obj2 (vlax-ename->vla-object (ssname sel2 (setq int2 (1- int2)))))
  13.     (progn (eq (vla-get-stylename obj2) "LDR_LS100_RED")
  14.        (vla-put-stylename obj2 "LDR_LS100")
  15.        )
  16.      )
  17.    )


What am I missing?


Code - Auto/Visual Lisp: [Select]
  1.  ...(progn (eq (vla-get-stylename obj1) "LDR_L100_RED")...
  2.  
  3.  
  4.  
  5.  ...(progn (eq (vla-get-stylename obj2) "LDR_LS100_RED")...
  6.  

Should be

Code - Auto/Visual Lisp: [Select]
  1.  ...(if (eq (vla-get-stylename obj1) "LDR_L100_RED")...
  2.  
  3.  
  4.  
  5.  
  6.  ...(if (eq (vla-get-stylename obj2) "LDR_LS100_RED")...
  7.  
7
AutoLISP (Vanilla / Visual) / multi-leader style change ?
« Last post by jlogan02 on November 23, 2020, 04:14:37 PM »
I'm clearly missing something here.

When I use these two routines as separate lisp routines, they work fine.

But if I place them together in the same lisp, both "RED" LDR's get changed to LDR_LS100.

Code - Auto/Visual Lisp: [Select]
  1.  (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))));;multi-leader
  2.    (repeat (setq int1 (sslength sel1))
  3.     (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  4.     (progn (eq (vla-get-stylename obj1) "LDR_L100_RED")
  5.        (vla-put-stylename obj1 "LDR_L100")
  6.        )
  7.      )
  8.    )
  9.  
  10.   (if (setq sel2 (ssget "_X" '((0 . "MULTILEADER"))));;multi-leader
  11.    (repeat (setq int2 (sslength sel2))
  12.     (setq obj2 (vlax-ename->vla-object (ssname sel2 (setq int2 (1- int2)))))
  13.     (progn (eq (vla-get-stylename obj2) "LDR_LS100_RED")
  14.        (vla-put-stylename obj2 "LDR_LS100")
  15.        )
  16.      )
  17.    )


What am I missing?
8
Dynamo / Re: There is a Dynamo section :-)
« Last post by lamarn on November 23, 2020, 02:46:08 PM »
@lamarn

on your picture there is manually added "AutoCAD" to the list. I'm surprised that pure Autocad also supports Dynamo?


It doesn't. You can create or read from AutoCAD objects but only in the Civil 3D environment.

Autodesk marketing at work! :( boooo Autodesk
9
CAD General / Re: ACI color drawing
« Last post by gherrman on November 23, 2020, 12:44:43 PM »
Could you post the associated .ctb file, presumably "WM_STD-02R.ctb"?
10
AutoLISP (Vanilla / Visual) / Re: Tool Palette Lisp for Setting Coordinates in Civil 3D
« Last post by MSTG007 on November 23, 2020, 08:07:28 AM »
Thanks for sharing Jeff!
Pages: [1] 2 3 ... 10