+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Junior Member
    Computer Details
    andy81's Computer Details
    Operating System:
    XP , Win7
    Discipline
    Structural
    andy81's Discipline Details
    Occupation
    CAD Support
    Discipline
    Structural
    Using
    AutoCAD 2011
    Join Date
    Sep 2013
    Location
    Canada
    Posts
    10

    Default N/E Labeling with MText improvement

    Registered forum members do not see this ad.

    Hello, thank you for taking the time to look at my post.
    And thank you all for creating such a useful body of knowledge for beginners like myself to learn from.

    I have been searching around for a lesson on using MText in AutoLISP
    (admittedly i have found a few amazing examples) Lee Mac has posted several replies to similar question. sorry for bringing it up again, but these have been over my head a bit. I am hopping someone will take the time to apply the MText solution to the attached Lisp that i currently do understand. It uses the Text Command...I realize using commands is amateurish, but I am still learning

    Code:
    ; Northing & Easting labeling
    ; Ryan Anderson December 2013
    ; The Label will use the current Text Style and current Units Settings
    ; This Lisp borrows ideas from the tutorials I have been working through.
    ; http://www.afralisp.net/ http://lee-mac.com/ http://www.cadtutor.net/ http://www.cad-notes.com/
    
    
    (defun c:gln (/ p x y TxtPos)
    (command "_.MSPACE")
    (while
    (setq p (getpoint "Select a Northing Gridline:"))
    (command "_.PSPACE")
    (setq TxtPos (getpoint "Pick Label Location: "))
    (setq y (rtos (cadr p)))
    (setq y (strcat "N " y))
    (command "_TEXT" TxtPos "0" y "") ; I would prefer to use MText with a backbround mask and an offset
    )
    (princ)
    )
    (princ)
    
    (defun c:gle (/ p x y TxtPos)
    (command "_.MSPACE")
    (while
    (setq p (getpoint "
    Select an Easting Gridline:"))
    (command "_.PSPACE")
    (setq TxtPos (getpoint "
    Pick Label Location: "))
    (setq x (rtos (car p)))
    (setq x (strcat "E " x))
    (command "_TEXT" TxtPos "90" x "") ; I would prefer to use MText with a backbround mask and an offset
    )
    (princ)
    )
    (princ "Use GLN for Northings, and GLE for Eastings") ;Could both Northings and Eastings be done from one command?
    (princ)
    Cheers!
    and thanks again for your time.
    Andy.

  2. #2
    Junior Member
    Computer Details
    andy81's Computer Details
    Operating System:
    XP , Win7
    Discipline
    Structural
    andy81's Discipline Details
    Occupation
    CAD Support
    Discipline
    Structural
    Using
    AutoCAD 2011
    Join Date
    Sep 2013
    Location
    Canada
    Posts
    10

    Default

    Ok, I have figured out some of the solution to this. I used Lee Mac's test program
    http://www.cadtutor.net/forum/showth...xt-in-AutoLISP
    Code:
    (defun c:test (/ ent)
      (if (setq ent (car (entsel "\nSelect MTEXT: ")))
        (foreach x (entget ent)
          (print x)))
      (textscr)
      (princ))
    to dump out the Dotted Pairs of MText that suited my needs. Trial and error brought me to understand the MText better when using entmake
    my LISP looks like this now.
    Code:
    ; Northing & Easting labeling with MText
    ; Ryan Anderson December 2013
    ; This Lisp borrows ideas from the tutorials I have been working through.
    ; http://www.afralisp.net/ http://lee-mac.com/ http://www.cadtutor.net/ http://www.cad-notes.com/
    
    
    (defun c:gln (/ p x y TxtPos)
    (command "_.MSPACE")
    (while
    (setq p (getpoint "Select a Northing Gridline: "))
    (command "_.PSPACE")
    (setq TxtPos (getpoint "Pick Label Location: "))
    (setq y (rtos (cadr p)))
    (setq y (strcat "N " y))
    (entmake
      (list
      (cons 0 "MTEXT")
      (cons 5 "549c")
      (cons 100 "AcDbEntity")
      (cons 67 1)
      (cons 410 "Layout1")		        ;Model space or layout tab to place MText on
      (cons 8 "TXT-GEN")			;Layer
      (cons 100 "AcDbMText")
      (cons 10 TxtPos)			;Location of text
      (cons 40 5.0)				;Font Height
    ; (cons 41 50)				;length of MText Field, if unspecified it will grow or shrink with the input length
      (cons 46 0.0)
      (cons 71 7)	                        ;Text Justification inside MText (1 is top left 7 is bottom left)
      (cons 72 5)
      (cons 1 y)				        ;Text Writen in MText Field
      (cons 7 "Text-03")			;Text Style
      (cons 210 '(0.0 0.0 1.0))
      (cons 11 '(1.0 0.0 0.0))
      (cons 43 5)
      (cons 50 0.0)			        ;Rotation of Text for North Coordinate labels
      (cons 73 1)
      (cons 44 1.0)
      (cons 90 3)			        ;Mask color 3 is "use drawing background color"
      (cons 63 256)				;Turns on background Mask
      (cons 45 1.5)				;Border offset Factor of Background Mask
      (cons 441 0)				;Something to do with background Mask
    )
    )
    (command "_.MSPACE")
    )
    (princ)
    )
    (princ)
    
    (defun c:gle (/ p x y TxtPos)
    (command "_.MSPACE")
    (while
    (setq p (getpoint "Select an Easting Gridline: "))
    (command "_.PSPACE")
    (setq TxtPos (getpoint "Pick Label Location: "))
    (setq x (rtos (car p)))
    (setq x (strcat "E " x))
    (entmake
      (list
      (cons 0 "MTEXT")
      (cons 5 "549c")
      (cons 100 "AcDbEntity")
      (cons 67 1)
      (cons 410 "Layout1")		        ;Model space or layout tab to place MText on
      (cons 8 "TXT-GEN")			;Layer
      (cons 100 "AcDbMText")
      (cons 10 TxtPos)			;Location of text
      (cons 40 5.0)				;Font Height
    ; (cons 41 50)				;length of MText Field, if unspecified it will grow or shrink with the input length
      (cons 46 0.0)
      (cons 71 7)				;Text Justification inside MText (1 is top left 7 is bottom left)
      (cons 72 5)
      (cons 1 x)					;Text Writen in MText Field
      (cons 7 "Text-03")			;Text Style
      (cons 210 '(0.0 0.0 1.0))
      (cons 11 '(1.0 0.0 0.0))
      (cons 43 5)
      (cons 50 1.5708)			;Rotation of Text for East Coordinate labels
      (cons 73 1)
      (cons 44 1.0)
      (cons 90 3)				;Mask color 3 is "use drawing background color"
      (cons 63 256)				;Turns on background Mask
      (cons 45 1.5)				;Border offset Factor of Background Mask
      (cons 441 0)				;Something to do with background Mask
    )
    )
    (command "_.MSPACE")
    )
    (princ)
    )
    (princ "Use GLN for Northings, and GLE for Eastings") ;Could both Northings and Eastings be done from one command?
    (princ)
    One last problem I am having. I hope someone can help me out. The location of the label is stored in the variable TxtPos. What i want is to be able to offset the text so it does not sit directly on the grid line I have selected. something like adding 5mm to the Y value of TxtPos for Northings and 5mm to the X Value for Eastings.

    Any help would be appreciated, if there was a simpler way of doing all this, please do not hesitate to correct me.
    lastly, if the code is useful for anyone please feel free to use it.
    cheers!
    Andy.

  3. #3
    Senior Member
    Discipline
    Civil
    Hippe013's Discipline Details
    Occupation
    Survey Crew Chief / Civil Designer
    Discipline
    Civil
    Details
    Land Survey / Civil Engineering
    Using
    Civil 3D 2017
    Join Date
    Feb 2010
    Location
    North Dakota
    Posts
    375

    Default

    Quote Originally Posted by andy81 View Post
    Code:
    (defun c:gln (/ p x y TxtPos)
    (command "_.MSPACE")
    (while
    (setq p (getpoint "Select a Northing Gridline: "))
    (command "_.PSPACE")
    (setq TxtPos (getpoint "Pick Label Location: "))
    If I have this correct you want to pick a point in Model Space retrieve the Northing and Easting and then toggle over to an active layout and place the text.

    May I offer a different approach to toggling between model and layout?

    Code:
    (vl-load-com);Load Visual Lisp Extensions
    (setq *acad* (vlax-get-acad-object));Get the ACAD Object
    (setq *ad* (vla-get-ActiveDocument *acad*));Get the Active Document
    (vlax-put-property *ad* 'ActiveSpace 1);For ModelSpace
    (vlax-put-property *ad* 'ActiveSpace 0);For Paperspace
    (vlax-release-object *acad*);release object when done using it
    (vlax-release-object *ad*);release object when done using it
    I would even recommend using the objects for creating your MTEXT.

  4. #4
    Junior Member
    Computer Details
    andy81's Computer Details
    Operating System:
    XP , Win7
    Discipline
    Structural
    andy81's Discipline Details
    Occupation
    CAD Support
    Discipline
    Structural
    Using
    AutoCAD 2011
    Join Date
    Sep 2013
    Location
    Canada
    Posts
    10

    Smile

    Thanks for your reply Hippe013.
    to be clear. I do want to pick a point in Model Space and retrieve the Northing and Easting, but I am doing this through a viewport located on Layout1.

    Sorry that was not documented at all. (Hopefully this will help others who read this post)

    The Drawing, with it's Drawing boarder is sitting on Layout 1
    one or more Viewports exist in the paperspace (Layout1) looking into Model space.
    All Annotations are required to be in Paper space.
    All Gridlines Exist in Model Space.

    So the work flow is:
    -Type in Either GLE (Eastings) or GLN (Northings)
    -Lisp will switch to model space in the viewport
    -prompt to pick a Gridline
    -Lisp will switch back to paper Space in Viewport
    -prompt to pick a label location
    -use the prefix of "E " for Eastings or "N " for Northings
    -create a MText at the picked point in Paper space
    -something like "E 1500.000" or "N 2400.000"
    -Easting Text is Rotated to be vertical
    -A background mask the same as the background color is applied

    Thanks for the code on Visual Lisp Extensions.
    I do not exactly follow at the moment, but I will dig deeper into it.
    If you have time (or if someone else wants to help out) i'd like to know what MText would look like in this format.

    cheers,
    Andy.

  5. #5
    Senior Member
    Discipline
    Civil
    Hippe013's Discipline Details
    Occupation
    Survey Crew Chief / Civil Designer
    Discipline
    Civil
    Details
    Land Survey / Civil Engineering
    Using
    Civil 3D 2017
    Join Date
    Feb 2010
    Location
    North Dakota
    Posts
    375

    Default

    Maybe try this? I hope that it helps with understanding VLA objects.

    Code:
    (vl-load-com);Load Visual Lisp Extensions
    
    (defun c:glne ()
      
      (setq *acad* (vlax-get-acad-object));Get the acad object
    
      (setq *ad* (vlax-get-property *acad* 'ActiveDocument));Get the Active Document
    
      (setq *PS* (vlax-get-property *ad* 'PaperSpace));Get the Active Paper Space
    
      (vlax-put-property *ad* 'ActiveSpace 1);Go to Model Space
    
      (setq pnt (getpoint "\Select Point on Grid: "));Prompt User to Select Point:
    
      (if pnt
        (progn ;If Point Exists
    
          (vlax-put-property *ad* 'ActiveSpace 0);Go to Paper Space
          
          (setq x (car pnt));Get the X value of Point
          
          (setq y (cadr pnt));Get the Y Value of Point
    
          (initget 1 "Northing Easting");Initialize getkword
    
          (setq ret (getkword "Label Northing or Easting?"));Ask user if they are labeling Northing or Easting
    
          (cond
    	((= ret "Northing")(setq str (strcat "N:" (rtos y 2 2)) rot 0))
    	((= ret "Easting")(setq str (strcat "E:" (rtos x 2 2)) rot (/ pi 2.0))));Format the string accordingly and Set the Roation
    
          (setq txtpos (getpoint "\nSelect Label Position:"));Prompt User for Label Position
    
          (if txtpos
    	(progn ;If Point Exists
    
    	  (setq MTEXT-OBJECT (vlax-invoke-method *PS* 'AddMText (vlax-3d-point txtpos) 1 str));Create the MTEXT Object
    
    	  (vlax-put-property MTEXT-OBJECT 'Layer "TXT-GEN");Set the layer for the MText
    
    	  (vlax-put-property MTEXT-OBJECT 'Height 0.12);Set the Text Height
    
    	  (vlax-put-property MTEXT-OBJECT 'BackgroundFill :vlax-true);Set the BackgroundFill to true
    
    	  (vlax-put-property MTEXT-OBJECT 'AttachmentPoint acAttachmentPointBottomLeft);Set the Jusstification
    
    	  (vlax-put-property MTEXT-OBJECT 'InsertionPoint (vlax-3d-Point txtpos));Reset the InsertionPoint
    
    	  (vlax-put-property MTEXT-OBJECT 'Rotation rot);Set the rotation
    	  
    	  (vlax-release-object *acad*)
    	  (vlax-release-object *ad*)
    	  (vlax-release-object *PS*)
    	  (vlax-release-object MTEXT-OBJECT)
    	  ;Not sure if its necessary to release every object or just *acad*
    	  ;either way... it doesn't hurt to just release it
    	  
    	  );end progn
    	
    	;if Point doesn't exist
    	
    	);end if
    
          );end progn
    
        ;if Point doesn't exist
    
        );end if
    
      );end defun

  6. #6
    Senior Member
    Discipline
    Civil
    Hippe013's Discipline Details
    Occupation
    Survey Crew Chief / Civil Designer
    Discipline
    Civil
    Details
    Land Survey / Civil Engineering
    Using
    Civil 3D 2017
    Join Date
    Feb 2010
    Location
    North Dakota
    Posts
    375

    Default

    This will help in looking at entities as objects.

    Code:
    (vl-load-com)
    (defun c:dmpobj ()
      (vlax-dump-object (vlax-ename->vla-object (car (entsel "\nSelect Object:"))) T)
      (command "TextScr")
      (princ)
      )

  7. #7
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,882

    Default

    A couple of suggestions

    Code:
    ; use POLAR to work out a new insert pt for the text
    (setq txtpos (polar (polar P 5.0 0.0) -5.0 1.5707963)
     
    (setq y (rtos (cadr p)))
    (setq y (rtos (cadr p) 2 0)) ; this is integer
    (setq y (rtos (cadr p)1 1)) ; this is 1 decimal place
    A man who never made mistakes never made anything

  8. #8
    Junior Member
    Computer Details
    andy81's Computer Details
    Operating System:
    XP , Win7
    Discipline
    Structural
    andy81's Discipline Details
    Occupation
    CAD Support
    Discipline
    Structural
    Using
    AutoCAD 2011
    Join Date
    Sep 2013
    Location
    Canada
    Posts
    10

    Smile

    Registered forum members do not see this ad.

    Thanks Hippe013 and BIGAL
    these code snippets look like they will be very helpful.

    when i get a little more time later in the week i will try to use the VLA method to solve this probelm again. with the offets this time
    cheers guys!
    Andy

Similar Threads

  1. hardware improvement suggestions
    By Enigma in forum Hardware & Operating Systems
    Replies: 52
    Last Post: 5th Feb 2014, 10:04 pm
  2. labeling using autolisp
    By autocrap in forum AutoLISP, Visual LISP & DCL
    Replies: 28
    Last Post: 18th May 2011, 10:27 pm
  3. AutoCAD 2007 Hotfix - Plotting to Raster Files Performance Improvement
    By Between the Lines in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 3rd Oct 2006, 05:50 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts