Jump to content

Field to mark mline style


mdbdesign

Recommended Posts

Create lots of mline styles to draw piping for shop details.

Now I am kind of lost which one is which one.

I think field is my solution to label all pipes (mline style) used.

Manually is OK but I need to speed-up process of marking.

Because this is my first contact with field I am lost again.

Field macro (?) is as below (from field dialog box):

(%<\AcObjProp Object(%<\[color=red]_ObjId 2128066088[/color]>%).StyleName \f "%tc1">%)

where red colored part is object ID.

Try to script it but it stop on opening dialog box for field.

field
object
select
mline style
uppercase

Any idea to automatize labeling?

Like:

push button (command)

select object

pick insertion point

...and go to next.

Thank you.:D

Link to comment
Share on other sites

I don't believe there is a command-line version of the Field command, so you will need to create the field using ActiveX methods.

 

Here is a quick example:

 

(defun c:mlfield ( / dc en pt )
   (while
       (progn
           (while
               (progn (setvar 'ERRNO 0) (setq en (car (entsel "\nSelect MLine: ")))
                   (cond
                       (   (= 7 (getvar 'ERRNO)) (princ "\nMissed, try again."))
                       (   (eq 'ENAME (type en))
                           (if (not (eq "MLINE" (cdr (assoc 0 (entget en)))))
                               (princ "\nPlease Select an MLine.")
                           )
                       )
                   )
               )
           )
           (if (and en (setq pt (getpoint "\nSpecify Point for Field: ")))
               (vla-addtext
                   (   (if (= 1 (getvar 'CVPORT)) vla-get-paperspace vla-get-modelspace)
                       (setq dc (vla-get-activedocument (vlax-get-acad-object)))
                   )
                   (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                       (if
                           (and
                               (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                               (vlax-method-applicable-p (vla-get-utility dc) 'getobjectidstring)
                           )
                           (vla-getobjectidstring (vla-get-utility dc) (vlax-ename->vla-object en) :vlax-false)
                           (itoa (vla-get-objectid (vlax-ename->vla-object en)))
                       )
                       ">%).StyleName \\f \"%tc1\">%"
                   )
                   (vlax-3D-point (trans pt 1 0)) (getvar 'TEXTSIZE)
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

Link to comment
Share on other sites

Wow, thank you, that was fast.

How do I will know to use any:

(vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))

OMG...

Thank you again :beer:

Link to comment
Share on other sites

You're welcome :)

 

How do I will know to use any:

(vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))

OMG...

 

Actually, that part is not necessary if you know for sure that the routine will only be used on either 64-bit or 32-bit (and not across both); since the methods for obtaining the ObjectID are necessarily different for 32-bit / 64-bit platforms.

 

For a 32-bit platform, you would use:

 

(itoa (vla-get-objectid <VLA-Object>))

However, this will not work in a 64-bit environment. Even using the alternative vla-get-objectid32 will not suffice since the conversion to a string will impose a 32-bit limit on the integer.

 

So instead we use:

 

(vla-getobjectidstring <Utility Object> <VLA-Object> <Hexadecimal?>)

Link to comment
Share on other sites

As an extension of the program I have posted in this thread, I have created a 'Quick Field' program. This program will allow you to very quickly create custom field commands for this kind of task.

 

The program page on my site describes the program in a lot more detail - have a read and let me know if you have any problems using the program :)

 

Lee

Link to comment
Share on other sites

  • 1 year later...

Was trying to reuse this code to insert block name field into dwg screen

Program asking to select block and again select block and nothing happen.

What I did wrong?

 

(defun c:blf ( / dc en pt )
   (while
       (progn
           (while
               (progn (setvar 'ERRNO 0) (setq en (car (entsel "\nSelect block: ")))
                   (cond
                       (   (= 7 (getvar 'ERRNO)) (princ "\nMissed, try again."))
                       (   (eq 'ENAME (type en))
                           (if (not (eq "block" (cdr (assoc 0 (entget en)))))
                               (princ "\nPlease Select an block.")
                           )
                       )
                   )
               )
           )
           (if (and en (setq pt (getpoint "\nSpecify Point for Field: ")))
               (vla-addtext
                   (   (if (= 1 (getvar 'CVPORT)) vla-get-paperspace vla-get-modelspace)
                       (setq dc (vla-get-activedocument (vlax-get-acad-object)))
                   )
                   (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                       (if
                           (and
                               (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                               (vlax-method-applicable-p (vla-get-utility dc) 'getobjectidstring)
                           )
                           (vla-getobjectidstring (vla-get-utility dc) (vlax-ename->vla-object en) :vlax-false)
                           (itoa (vla-get-objectid (vlax-ename->vla-object en)))
                       )
					 ">%)._EffectiveName \\f \"%tc4"
                   )
                   (vlax-3D-point (trans pt 1 0)) (getvar 'TEXTSIZE)
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

Link to comment
Share on other sites

Ok, resolved with "QuickField" but still would like to know, what is wrong with above codes (BLF)

 

This:

(not (eq "block" (cdr (assoc 0 (entget en)))))

Should be:

(not (eq "INSERT" (cdr (assoc 0 (entget en)))))

 

And this:

">%)._EffectiveName \\f \"%tc4"

Should be:

">%).EffectiveName \\f \"%tc4\">%"

Link to comment
Share on other sites

I changed as per instruction (I think so):

(defun c:blf ( / dc en pt )
   (while
       (progn
           (while
               (progn (setvar 'ERRNO 0) (setq en (car (entsel "\nSelect block: ")))
                   (cond
                       (   (= 7 (getvar 'ERRNO)) (princ "\nMissed, try again."))
                       (   (eq 'ENAME (type en))
                           (if (not (eq "INSERT" (cdr (assoc 0 (entget en)))))
                               (princ "\nPlease Select an block.")
                           )
                       )
                   )
               )
           )
           (if (and en (setq pt (getpoint "\nSpecify Point for Field: ")))
               (vla-addtext
                   (   (if (= 1 (getvar 'CVPORT)) vla-get-paperspace vla-get-modelspace)
                       (setq dc (vla-get-activedocument (vlax-get-acad-object)))
                   )
                   (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                       (if
                           (and
                               (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                               (vlax-method-applicable-p (vla-get-utility dc) 'getobjectidstring)
                           )
                           (vla-getobjectidstring (vla-get-utility dc) (vlax-ename->vla-object en) :vlax-false)
                           (itoa (vla-get-objectid (vlax-ename->vla-object en)))
                       )
                        ">%).EffectiveName \\f \"%tc4\">%"
                   )
                   (vlax-3D-point (trans pt 1 0)) (getvar 'TEXTSIZE)
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

 

and show me "too many arguments" error. What I screw up now?

Edited by mdbdesign
Code updated with "if", code updated again - WORKING
Link to comment
Share on other sites

I never said to remove the if ;) :

 

(not (eq "INSERT" (cdr (assoc 0 (entget en))))
   (princ "\nPlease Select an block.")
)

should be:

(if (not (eq "INSERT" (cdr (assoc 0 (entget en)))))
   (princ "\nPlease Select an block.")
)

Link to comment
Share on other sites

I did find it on floor, must fall when copy and paste, saved before "if" disappear in vacuum. ;)

Sorry, I am late but my new living room set just arrived and got little fun (read: assembly) with it.

Lee, I add "if" and got bushes (####) when insert text. Is it has anything to do with field formatting?!?!?!

Sorry Lee, but this is my beginning with field:?

 

Code in post #10 updated, line 9 (if (not (eq "INSERT" (cdr (assoc 0 (entget en)))))

Link to comment
Share on other sites

I did find it on floor, must fall when copy and paste, saved before "if" disappear in vacuum. ;)

 

:lol:

 

Lee, I add "if" and got bushes (####) when insert text. Is it has anything to do with field formatting?!?!?!

 

I noticed another change that was not required....

"%<\\AcObjProp Object(%<\\effectiveName"

should remain as:

"%<\\AcObjProp Object(%<\\_ObjId "

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