Jump to content

lisp routine for curly bracket around text


todouble22

Recommended Posts

I was hoping someone could help me to write a lisp to draw a curly bracket } that will stretch from a start point to an end point as kind of a way to include all text that are associated with one label. does that make sense??:shock: It would be similar to how the express tools breakline works but instead of the angles putting the arcs in the midpoint of the start and end point.. I saw some code for it a while back but cant find anything again? In advance I appreciate all your help..

Link to comment
Share on other sites

I don't see why not? I'll double check but it would be great to look at whatever you have. I'm working on getting better at vb anyhow..

Link to comment
Share on other sites

Hi,

 

Here's a quicky.

 

(defun c:curly (/ p1 p2 a0 a1 a2 d)
 (and
   (setq p1 (getpoint "\nFirst point: "))
   (setq p2 (getpoint p1 "\nSecond point: "))
   (setq a0 (angle p1 p2)
         a1 (- a0 (/ pi 12.))
         a2 (+ a0 pi (/ pi 12.))
         d  (/ (/ (/ (distance p1 p2) 2.) (cos (/ pi 12.))) 2.)
   )
   (entmake
     (list
       '(0 . "LWPOLYLINE")
       '(100 . "AcDbEntity")
       '(100 . "AcDbPolyline")
       '(90 . 5)
       '(70 . 0)
       (cons 10 p1)
       '(42 . 0.6)
       (cons 10 (polar p1 a1 d))
       '(42 . -0.6)
       (cons 10 (polar p1 a1 (* 2. d)))
       '(42 . -0.6)
       (cons 10 (polar p2 a2 d))
       '(42 . 0.6)
       (cons 10 p2)
     )
   )
 )
 (princ)
)

  • Like 1
Link to comment
Share on other sites

Side note: I did it as a dynamic block and it works fine but the boss wants it done a specific way I guess

 

Don't laugh - this one is from my very oldies :)

 

(defun my_error_f  (msg)
 (setq *error* olderr_f)
 (if svfrad
   (setvar "filletrad" svfrad))
 (if svosmode
   (setvar "osmode" svosmode))
 (setvar "cmdecho" 1)  
 (print (strcat "error:" msg))
 (prin1)
 )

(defun C:CBR (/ *error* ang cp1 cp2 cpt ep2 ept
        lp my_error_f olderr_f r resp rf
        sp1 spt svfrad svosmode upt)
		
 (setq svosmode (getvar "osmode"))
 (setvar "osmode" 0)		
 (setq svfrad (getvar "filletrad"))
 
 (setq olderr_f *error*
*error* my_error_f)	

 (setvar "cmdecho" 0)

(command "_ortho" "_on")

(setq r 4.0 rf
      (* 1.125 r)
     )
 (initget 1 "Left Right")
 (setq resp (getkword "\nChoose a braket position [Left/Right]: "))
 (setq spt (getpoint "\nSpecify upper point : ")
     ept (getpoint spt "\nSpecify lower point : ")
     lp (distance spt ept)
     )
(if
 (eq resp "Left")
(progn
(setq sp1 (polar spt pi rf))
(setq ep2 (polar ept pi  rf))
(setq cpt (polar sp1 (* pi 1.5) ( / lp 2.0))
     upt (polar cpt pi rf))
(setq cp1 (polar cpt (/ pi 2) ( / rf 2.0)))
(setq cp2 (polar cpt (* pi 1.5) ( / rf 2.0)))
)
 (progn
(setq sp1 (polar spt 0 rf))
(setq ep2 (polar ept 0  rf))
(setq cpt (polar sp1 (* pi 1.5) ( / lp 2.0))
     upt (polar cpt 0 rf))
(setq cp1 (polar cpt (/ pi 2) ( / rf 2.0)))
(setq cp2 (polar cpt (* pi 1.5) ( / rf 2.0)))
)
 )
(command "_.osnap" "_none" "")
(command "_.pline")(mapcar 'command (list spt sp1 cp1 upt cp2 ep2 ept)) (command "")
(setvar "filletrad" r)
(command "_.fillet" "_P" "_L")
(princ)
 )

 

~'J'~

Link to comment
Share on other sites

A nicer one, in C#

Attached the DLL to netload.

 

using System;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace CurlyJigSample
{
   public class Command
   {
       class CurlyJig : EntityJig
       {
           Polyline m_pline;
           Point3d m_dragPt;
           Point2d p0;
           Vector2d xDir = new Vector2d(1.0, 0.0);

           public CurlyJig(Polyline pline, Point3d dragPt, Point2d pt)
               : base(pline)
           {
               m_pline = pline;
               m_dragPt = dragPt;
               p0 = pt;
           }

           protected override bool Update()
           {
               Point2d p4 = new Point2d(m_dragPt.X, m_dragPt.Y);
               double d = (p0.GetDistanceTo(p4) / 2.0) / (Math.Cos(Math.PI / 12.0));
               Vector2d vec = p0.GetVectorTo(p4);
               double a0 = p4.Y < p0.Y ?
                   (Math.PI * 2.0) - xDir.GetAngleTo(vec) :
                   xDir.GetAngleTo(vec);
               m_pline.SetPointAt(1, Polar(p0, a0 - (Math.PI / 12.0), d / 2.0));
               m_pline.SetPointAt(2, Polar(p0, a0 - (Math.PI / 12.0), d));
               m_pline.SetPointAt(3, Polar(p4, a0 + Math.PI + (Math.PI / 12.0), d / 2.0));
               m_pline.SetPointAt(4, p4);
               return true;
           }

           protected override SamplerStatus Sampler(JigPrompts prompts)
           {
               JigPromptPointOptions jppo = new JigPromptPointOptions("\nSpecify the second point: ");
               jppo.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.GovernedByOrthoMode);
               PromptPointResult ppr = prompts.AcquirePoint(jppo);
               if (ppr.Status == PromptStatus.OK)
               {
                   if (ppr.Value.IsEqualTo(m_dragPt))
                       return SamplerStatus.NoChange;
                   else
                   {
                       m_dragPt = ppr.Value;
                       return SamplerStatus.OK;
                   }
               }
               return SamplerStatus.Cancel;
           }
       }

       private static Point2d Polar(Point2d org, double angle, double distance)
       {
           return new Point2d(org.X + (distance * Math.Cos(angle)), org.Y + (distance * Math.Sin(angle)));
       }

       [CommandMethod("CURLY")]
       public void CURLY()
       {
           Document doc = Application.DocumentManager.MdiActiveDocument;
           Database db = doc.Database;
           Editor ed = doc.Editor;
           PromptPointResult ppr = ed.GetPoint("\nSpecify the first point: ");
           if (ppr.Status == PromptStatus.OK)
           {
               using (Transaction tr = db.TransactionManager.StartTransaction())
               {
                   Point3d picked = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
                   Point2d pt = new Point2d(picked.X, picked.Y);
                   Polyline pline = new Polyline(5);
                   pline.AddVertexAt(0, pt, 0.6, 0.0, 0.0);
                   pline.AddVertexAt(1, pt, -0.6, 0.0, 0.0);
                   pline.AddVertexAt(2, pt, -0.6, 0.0, 0.0);
                   pline.AddVertexAt(3, pt, 0.6, 0.0, 0.0);
                   pline.AddVertexAt(4, pt, 0.0, 0.0, 0.0);
                   CurlyJig jig = new CurlyJig(pline, picked, pt);
                   PromptResult pr = ed.Drag(jig);
                   if (pr.Status == PromptStatus.OK)
                   {
                       BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                       btr.AppendEntity(pline);
                       tr.AddNewlyCreatedDBObject(pline, true);
                   }
                   tr.Commit();
               }
           }
       }
   }
}

CurlyJig.zip

Link to comment
Share on other sites

  • 4 years later...

HELP!

 

I used to have this nice brace command that would prompt the user for three things

 

1. start point

2. end point

3. fillet radius

 

it would then draw a straight line brace that was filleted at the ends and the middle

The ends would curl to the right through 90 degrees and the middle ends would curl to the left making the classic brace {

 

The lines in between would remain straight.

 

for some reason it has stopped working in 2011

 

 

 

(DEFUN C:BRAC ()

(INITGET 1)(SETQ A (GETPOINT "\nStarting Point: "))

(INITGET 1)(SETQ B (GETPOINT A "\nEnding Point: "))

(SETQ C (/ (DISTANCE A B) 2))

(SETQ D (GETDIST (STRCAT "\nFillet Radius :")))

(IF (NULL D) (SETQ D (+ 0.01 (GETVAR "FILLETRAD"))) (SETQ D (+ 0.01 D)))

(SETVAR "FILLETRAD" (- D 0.01))

(SETQ E (ANGLE B A))

(SETQ F (+ 1.570796 E))

(COMMAND "PLINE" B (POLAR B F D)

(POLAR (GETVAR "LASTPOINT") E C)

(POLAR (GETVAR "LASTPOINT") F D) \r)

(SETQ F (- F PI))

(COMMAND "LINE" "@" (POLAR (GETVAR "LASTPOINT") F D)

(POLAR (GETVAR "LASTPOINT") E C)

(POLAR (GETVAR "LASTPOINT") F D) \r)

(COMMAND "FILLET" "P" "@")

(COMMAND "FILLET" "P" B)

)

 

 

Thanks in advance

 

markhamilton5@att.net

Link to comment
Share on other sites

What needs to happen is that a user is prompted for top point, bottom point, left/right, fillet radius (possibly) then the pline needs to be cut into two plines... each pline needs to be filleted separtly

 

building on what you all have shown this is what I have so far...

 

;(DEFUN C:BRAC ()

;(INITGET 1)(SETQ A (GETPOINT "\nStarting Point: "))

;(INITGET 1)(SETQ B (GETPOINT A "\nEnding Point: "))

;(SETQ C (/ (DISTANCE A B) 2))

;(SETQ D (GETDIST (STRCAT "\nFillet Radius :")))

;(IF (NULL D) (SETQ D (+ 0.01 (GETVAR "FILLETRAD"))) (SETQ D (+ 0.01 D)))

;(SETVAR "FILLETRAD" (- D 0.01))

;(SETQ E (ANGLE B A))

;(SETQ F (+ 1.570796 E))

;(COMMAND "PLINE" B (POLAR B F D)

; (POLAR (GETVAR "LASTPOINT") E C)

; (POLAR (GETVAR "LASTPOINT") F D) \r)

;(SETQ F (- F PI))

;(COMMAND "LINE" "@" (POLAR (GETVAR "LASTPOINT") F D)

; (POLAR (GETVAR "LASTPOINT") E C)

; (POLAR (GETVAR "LASTPOINT") F D) \r)

;(COMMAND "FILLET" "P" "@")

;(COMMAND "FILLET" "P" B)

;)

 

 

 

 

(defun C:BRAC (/ *error* ang cp1 cp2 cpt ep2 ept

lp my_error_f olderr_f r resp rf

sp1 spt svfrad svosmode upt)

 

(setq svosmode (getvar "osmode"))

(setvar "osmode" 0)

(setq svfrad (getvar "filletrad"))

 

(setq olderr_f *error*

*error* my_error_f)

 

(setvar "cmdecho" 0)

 

(command "_ortho" "_on")

 

(IF (NULL D) (SETQ D (+ 0.01 (GETVAR "FILLETRAD"))) (SETQ D (+ 0.01 D)))

(SETVAR "FILLETRAD" (- D 0.01))

 

(setq r 0.25 rf (* D r))

 

(initget 1 "Left Right")

(setq resp (getkword "\nChoose a braket position [Left/Right]: "))

 

(setq spt (getpoint "\nSpecify upper point : ")

ept (getpoint spt "\nSpecify lower point : ")

lp (distance spt ept)

)

 

(if

(eq resp "Left")

(progn

(setq sp1 (polar spt pi rf))

(setq ep2 (polar ept pi rf))

(setq cpt (polar sp1 (* pi 1.5) ( / lp 2.0)) upt (polar cpt pi rf))

(setq cp1 (polar cpt (/ pi 2) ( / rf 2.0)))

(setq cp2 (polar cpt (* pi 1.5) ( / rf 2.0)))

)

 

(progn

(setq sp1 (polar spt 0 rf))

(setq ep2 (polar ept 0 rf))

(setq cpt (polar sp1 (* pi 1.5) ( / lp 2.0)) upt (polar cpt 0 rf))

(setq cp1 (polar cpt (/ pi 2) ( / rf 2.0)))

(setq cp2 (polar cpt (* pi 1.5) ( / rf 2.0)))

)

)

 

(command "osnap" "_none" "")

(command "_.Pline")(mapcar 'command (list spt sp1 cp1 upt cp2 ep2 ept)) (command "")

(setvar "filletrad" r)

(command "_.fillet" "_P" "_L")

(princ)

 

)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...