Jump to content

Insert value returned by lisp to drawing on screen


Recommended Posts

Posted

I'm using this code to measure distance with consecutive clicks. It is like the dist command but allows me to measure polylines (zig-zag), add predefined constants and insert a value form keyboard and the total (tot2) is displayed in a dcl window.

 

I need help to insert this value (tot2) in the drawing in a position that would be determined by clicking on screen.

 

This way I would eliminate the dcl window and the trouble to write the value (tot2) manually on the drawing.

 

I need help to add error traps as well.

 

 

 v 300.1.1prad
;cumulative distance
;this routine is just like the Autocad Distance command with the
;exception that it allows you to pick more than 2 consecutive points.
;the routine will display the cumulative distance and the distance
;between the last two points picked on the command line.
;it will add predefined constants and ask for values to add to distance measured
;and show results in a dcl window

;

(defun c:sq ()
(setvar "cmdecho" 0)
(graphscr)

(setq
   a1 0.30
   a2 0.10
   a3 0.10
   tolleranza 0.20
)
(princ "Discesa  ")
(princ a1)

(princ "  Massetto_1  ")
(princ a2)
(princ)

(princ "  Massetto_2  ")
(princ a3)
(princ)

(princ "  Tolleranza  ")
(princ tolleranza)
(princ)



(setq
 p1 (getpoint "\nPick start point ")
 p2 (getpoint p1 "\nPick next point ")
 d1 (distance p1 p2)
 prdist (strcat "\nDistance: " (rtos d1))
)

(princ prdist)

(setq p3 (getpoint p2 "\nPick next point or RETURN if done "))

(while p3

 (setq
  d0 (distance p2 p3)
  d1 (+ (distance p2 p3) d1)
  p2 p3
  prdist (strcat "\nDistance: " (rtos d0) ", Cumulative distance: " (rtos d1))
 )
 (princ prdist)
 (setq p3 (getpoint p2 "\nPick Next Point "))
)
(setq cumd (strcat "Distanza orrizontale --> " (rtos d1 2 2)))
(prompt cumd)
(princ)

(setq miodist (getdist "\n Insert Height "))
(princ "\n The height is ")
(princ (rtos miodist 2 2))
(princ)

(setq tot2 (+ a1 a2 a3 tolleranza miodist d1))
(setq pcumd (strcat "Grand distance --> " (rtos tot2 2 2)))
(princ "\n --> ")
(prompt pcumd)
(princ)

;(princ "\n la distance G.totale is ")
;(princ tot2)
;(princ)
;-------------start dialog------------
(setq dcl_id (load_dialog "hello_sp.dcl")) ; Load the DCL file.
 (if (not (new_dialog "hello_sp" dcl_id))   ; Initialize the dialog.
   (exit)                                ; Exit if this doesn't 
                                         ; work.
 )
;------------  set values in dialog box----

(set_tile "discesa" (rtos a1 2 2)) 
(set_tile "masetto1" (rtos a2 2 2))
(set_tile "salita" (rtos miodist 2 2))
 (set_tile "tolleranza" (rtos tolleranza 2 2))
(set_tile "grand_dist" (rtos tot2 2 2))
(set_tile "grand_dist_" "GRAND TOTAL (SQ)")
 

;------------  end - set values in dialog box----

 (start_dialog)                          ; Display the dialog 
                                         ; box.
(unload_dialog dcl_id)                  ; Unload the DCL file.


 (princ)

;------------------------

)
(princ "\nType sq to run Grand Distance(sq)")
(princ)

  • Replies 35
  • Created
  • Last Reply

Top Posters In This Topic

  • sadhu

    13

  • alanjt

    12

  • Lee Mac

    11

Posted

You can use something like this to add a text value, based on a specified point.

 

(and (setq pnt (getpoint "\nSpecify Text placement point: "))
    (entmakex (list '(0 . "MTEXT")
                    '(100 . "AcDbEntity")
                    '(100 . "AcDbMText")
                    (cons 1 tot2)
                    (cons 7 (getvar 'textstyle))
                    (cons 10 pnt)
              ) ;_ list
    ) ;_ entmakex
) ;_ and

Posted
Yes :thumbsup:

[code][quote]Rules rules rules. [/quote]

[/code]

 

...................

Posted

Hi alanjt , I get this error.

I just copied the code and pasted to the end of my lisp.

 

Specify Text placement point: ; error: bad DXF group: (1 . 15.472)

 

What does it mean ?

Posted

Try this instead:

 

(and (setq pnt (getpoint "\nSpecify Text placement point: "))
    (entmakex (list '(0 . "MTEXT")
                    '(100 . "AcDbEntity")
                    '(100 . "AcDbMText")
                    (cons 1 (rtos tot2 2 2))
                    (cons 7 (getvar 'textstyle))
                    (cons 10 pnt)
              ) ;_ list
    ) ;_ entmakex
) ;_ and

Posted
Hi alanjt , I get this error.

I just copied the code and pasted to the end of my lisp.

 

 

 

What does it mean ?

 

Sorry about that. I had just assumed you had/would convert it to a string.

 

Try this instead:

 

(and (setq pnt (getpoint "\nSpecify Text placement point: "))
    (entmakex (list '(0 . "MTEXT")
                    '(100 . "AcDbEntity")
                    '(100 . "AcDbMText")
                    (cons 1 (rtos tot2 2 2))
                    (cons 7 (getvar 'textstyle))
                    (cons 10 pnt)
              ) ;_ list
    ) ;_ entmakex
) ;_ and

Thanks Lee. :)

Posted

Thanks Lee:) Works perfect.

 

Is text height managed by this ?

 

(cons 10 pnt)

Posted
Thanks Lee:)

 

Is text height managed by this ?

 

NO, that's the insertion point.

For textsize: (cons 40 (getvar 'textsize))

or whatever you like.

Posted

Thanks again.

 

Just did this and got what I wanted :D:

 

(and (setq pnt (getpoint "\nSpecify Text placement point: "))
    (entmakex (list '(0 . "MTEXT")
                    '(100 . "AcDbEntity")
                    '(100 . "AcDbMText")
                    (cons 1 (rtos tot2 2 2))
                    (cons 7 (getvar 'textstyle))
                    (cons 10 pnt)
                    (cons 40 0.1)
              ) ;_ list
    ) ;_ entmakex
) ;_ and

Posted

Just for the record, if you specify the value instead of retrieving it from a variable, you can additionally call it like the following:

 

'(40 . 0.1)

Posted

Explanation of Alan's suggestion:

 

http://www.cadtutor.net/forum/showpost.php?p=258390&postcount=20

  • 2 weeks later...
Posted

I need to add two features to the code below:

  1. the text be visible along with the cursor before specifying "Text placement point" - so that I can see that the text does not overlap other objects nearby.
  2. be able to rotate Text (obviously not with the rotate command after insertion)

(and (setq pnt (getpoint "\nSpecify Text placement point: "))
    (entmakex (list '(0 . "MTEXT")
                    '(100 . "AcDbEntity")
                    '(100 . "AcDbMText")
                    ;(cons 8 lay)
                     (cons 1 (strcat "(" Edit1 Edit2 ")" (rtos tot2 2 2) Edit3))
                     (cons 7 (getvar 'textstyle))
                     (cons 10 pnt)
                     (cons 40 0.08)
              ) ;_ list
    ) ;_ entmakex
) ;_ and

Posted
I need to add two features to the code below:
  1. the text be visible along with the cursor before specifying "Text placement point" - so that I can see that the text does not overlap other objects nearby.

This would only be possible either through a grRead loop, or using the move command with a pause, or perhaps using pasteclip.

Posted

This would only be possible either through a grRead loop, or using the move command with a pause, or perhaps using pasteclip.

Don't forget about ACET-SS-Drag-Move. I only suggest this to allow the user the ability of being able to utilize OSnaps normally and avoid the annoyances of a right-click if using Move..Pause. However, it does require Express Tools to be loaded.

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...