Author Topic: blocks then text  (Read 1998 times)

0 Members and 1 Guest are viewing this topic.

CADEC70

  • Guest
blocks then text
« on: January 11, 2008, 10:14:04 PM »
I inserted a block..what I wanted to do is put the name of the block by just clicking the 'block'. Say I created a chair block, then inserted it on a drawing, then I want to put the label on it, by just simply clicking on the chair.
AND
 
Can it be on MTEXT?
is it possible to make the justification on 'middle centre'
and automatically rotate on 90 if the block is rotated
Thanks in advance

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: blocks then text
« Reply #1 on: January 12, 2008, 12:08:15 PM »
Constant attribute?
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: blocks then text
« Reply #2 on: January 12, 2008, 01:03:45 PM »
One could use a field, and select OBJECT> then pick the chair block>the select the block name.
Be your Best


Michael Farrell
http://primeservicesglobal.com/

adalea03

  • Guest
Re: blocks then text
« Reply #3 on: January 13, 2008, 08:00:16 AM »
Try code below.

Code: [Select]
;Places block name as text object; text is scaled to match dimension text
(defun c:bnn  (/ bname mynv-lst)
  (setq mynv-lst (mapcar '(lambda (x) (list x (getvar x)))
    '("clayer" "dimscale" "cmdecho" "osmode" "orthomode")))
  (setvar "cmdecho" 0) (setvar "osmode" 0) (setvar "orthomode" 0)
  (setq bname (vlax-get-property (vlax-ename->vla-object
    (car (entsel "\nSelect block to label:"))) "name"))
;;;  (setq bname (substr  1 (- (strlen bn) 2)))
  (command "mtext" (getpoint "\nSelect point for block name:")
           "h" (* (getvar "dimtxt") (getvar "dimscale"))
           "j" "mc" "w" 0 bname "")
  (command "move" (entlast) "" (getvar "lastpoint") "\\")
  (mapcar '(lambda (x) (setvar (car x) (cadr x))) mynv-lst)
  (princ)
  )

CADEC70

  • Guest
Re: blocks then text
« Reply #4 on: January 18, 2008, 01:06:57 PM »
Thanks!
Can I have another request,..is it possible to set the mtext width automatically after adding the text?

Thanks in advance

adalea03

  • Guest
Re: blocks then text
« Reply #5 on: January 20, 2008, 09:12:15 AM »
Did you try to edit the previous code?
Try to change the zero (after the "w") in the mtext command.
Also, the code should have had a (vl-load-com) statement near the begining.

Tony

adalea03

  • Guest
Re: blocks then text
« Reply #6 on: January 20, 2008, 09:34:33 AM »
Code: [Select]
;Places block name as text object; text is scaled to match dimension text
(defun c:bnn  (/ bname mynv-lst)
  (vl-load-com) ;added
  (setq mynv-lst (mapcar '(lambda (x) (list x (getvar x)))
    '("clayer" "dimscale" "cmdecho" "osmode" "orthomode")))
  (setvar "cmdecho" 0) (setvar "osmode" 0) (setvar "orthomode" 0)
  (setq bname (vlax-get-property (vlax-ename->vla-object
    (car (entsel "\nSelect block to label:"))) "name"))
;;; I use the next line of code to strip a 2 character suffix from our block names
;;; I have commented it here so that it doesn't strip 2 characters
;;;  (setq bname (substr  1 (- (strlen bn) 2)))
  (command "mtext" (getpoint "\nSelect point for block name:")
;;; the next line scales the mtext height to match dimension text
           "h" (* (getvar "dimtxt") (getvar "dimscale"))
           "j" "mc"
;;; the next line sets the width, change the zero to your liking
           "w" 0
           bname "")
;;; I use the next line to tweak the placement of the label
  (command "move" (entlast) "" (getvar "lastpoint") "\\")
  (mapcar '(lambda (x) (setvar (car x) (cadr x))) mynv-lst)
  (princ)
  )

Oops. Forgot to add the code to last post.
Tony

CADEC70

  • Guest
Re: blocks then text
« Reply #7 on: January 21, 2008, 12:36:24 PM »
Sorry I'm not really a lisp guy...
so

is it possible to set the mtext width automatically after adding the text?
I try to use the above lisp code, but you can't set the 'mtext width'

Thanks in advance

adalea03

  • Guest
Re: blocks then text
« Reply #8 on: January 21, 2008, 09:24:27 PM »
Each of the commands below will create mtext objects with different widths.
Copy and paste each one to the command line (press the enter key after each paste).
When done , select all the new text objects and observe the different widths.

Code: [Select]
(command "mtext" (getpoint "\nSelect point for block name:")
           "h" (* (getvar "dimtxt") (getvar "dimscale"))
           "j" "mc"
           "w" 12
           "my block name" "")
(command "mtext" (getpoint "\nSelect point for block name:")
           "h" (* (getvar "dimtxt") (getvar "dimscale"))
           "j" "mc"
           "w" 22
           "my block name" "")
(command "mtext" (getpoint "\nSelect point for block name:")
           "h" (* (getvar "dimtxt") (getvar "dimscale"))
           "j" "mc"
           "w" 44
           "my block name" "")
(command "mtext" (getpoint "\nSelect point for block name:")
           "h" (* (getvar "dimtxt") (getvar "dimscale"))
           "j" "mc"
           "w" 88
           "my block name" "")


If I have misunderstood your request, I may only be confusing the issue.
Hopefully, I don't lead you too far astray before a real "Swamper' pipes in.