Jump to content

Help to get coord off insertpoint in to blocks attribute


Recommended Posts

Posted

I need help with a lisp file that inserts a block, POS_OVERFALLSLARM.

I can manage that.

 

(defun c:pos_overfallslarm (/ pt)

(setq pt (getpoint "\nPick Insertion point."))

(command "_insert" "POS_OVERFALLSLARM.dwg" pt "" "" "")

)

 

But I want the x,y coordinates to be write in the attribute, POS.

I think that I can use car, adr and list to create a x,y list.

But how do I get it into the attribute???

 

(defun c:pos_glasbreak (/ pt)

(setq pt (getpoint "\nPick Insertion point."))

(setq ptx (car pt))

(setq pty (cadr pt))

(setq ptxy (list ptx pty))

(command "_insert" "POS_OVERFALLSLARM.dwg" pt "" "" "")

)

 

And how do I get the rotation into attribute ROT.

There are one more attribute, UNR, that I have to fill in by hand.

 

Hoping for help.

Erik

Posted

Hi,

 

You can use fields in the attribute definitions.

Posted

It has to be blocks.

Some GIS man has a script that extracts data from blocks named POS_xxx with attributes POS, ROT and UNR.

 

I'm not sure what fields means.

Posted

I haven't been able to test this yet but it should be roughly what you are looking for

 

(defun c:pos_overfallslarm (/ pt)
 ;Set the attribute name that stores the X value Alternatively replace line with (setq Xattrib "Name_of_attrib")
 (setq Xatrrib (getstring "\nWhich attribute should contain X Value? "))
 ;Same as above
 (setq Yatrrib (getstring "\nWhich attribute should contain Y Value? "))
 ;Set insertion point
 (setq pt (getpoint "\nPick Insertion point."))
 ;Insert block
 (command "_insert" "POS_OVERFALLSLARM.dwg" pt "" "" "")
 ;Get block that was previously inserted and create vla-object
 (setq blk (vlax-ename->vla-object (car(entlast))))
 ;Make sure block has attributes
 (if(= (vla-get-hasattributes blk) :vlax-true)
   ;If yes
  (progn
    ;With each attribute
    (foreach c (vlax-safearray->list(vla-getattributes blk))
      ;Compare case insensitive name against xattrib  and Y attrib
      (if(= (strcase Xattrib) (strcase(vla-get-name c)))
    ;Update the value if name matches
    (vla-put-textstring c (car(pt)))
      )
      (if(= (strcase Yattrib) (strcase(vla-get-name c)))
    (vla-put-textstring c (cadr(pt)))
      )
    )
  )
   ;If block contains no attributes
   (princ "\nBlock contains no attributes")
 )
 
 
)

Posted

Thanks for your help but I can't I get it to work.

The insert of the block works but no coordinates is in the attributes.

What I need is that both the x- and y-coordinates is in the attribute named POS (like x,y or 100,100).

And if I could get the rotation in to attribute ROT it would be perfekt.

  • 2 weeks later...
Posted

....the coordinates from the list ptxy looks like this:

2.237824430545935E+006,5.248335636246174E+006

I want to have it like this:

2237824.4,5248335.6

 

Can anyone help me to get the coordinates right???

 

The code looks like this:

(defun c:pos_overfallslarm (/ pt)

(setq pt (getpoint "\nPick Insertion point."))

(setq ptx (car pt))

(setq pty (cadr pt))

(setq ptxy (list ptx pty))

(SETVAR "ATTDIA" 0)

(command "_insert" "POS_OVERFALLSLARM.dwg" pt "" "" "" "" ptxy "")

(SETVAR "ATTDIA" 1)

)

Posted

I think I'd try something like this:

 

[b][color=BLACK]([/color][/b]defun c:infill [b][color=FUCHSIA]([/color][/b]/ bn en ed ip px py pz ra an ad tn[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]or [b][color=MAROON]([/color][/b]not bn[b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]snvalid bn[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]or [b][color=BLUE]([/color][/b]tblsearch [color=#2f4f4f]"BLOCK"[/color] bn[b][color=BLUE])[/color][/b]
                     [b][color=BLUE]([/color][/b]findfile [b][color=RED]([/color][/b]strcat bn [color=#2f4f4f]".DWG"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq bn [b][color=MAROON]([/color][/b]getstring [color=#2f4f4f]"\nBlock To INSERT:   "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setvar [color=#2f4f4f]"CMDECHO"[/color] 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]"_.INSERT"[/color] bn[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]> [b][color=MAROON]([/color][/b]getvar [color=#2f4f4f]"CMDACTIVE"[/color][b][color=MAROON])[/color][/b] 0[b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]command pause[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setvar [color=#2f4f4f]"CMDECHO"[/color] 0[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]assoc 66 [b][color=MAROON]([/color][/b]entget [b][color=GREEN]([/color][/b]entlast[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]setq en [b][color=MAROON]([/color][/b]entlast[b][color=MAROON])[/color][/b]
            ed [b][color=MAROON]([/color][/b]entget en[b][color=MAROON])[/color][/b]
            ip [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 10 ed[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
            px [b][color=MAROON]([/color][/b]car ip[b][color=MAROON])[/color][/b]
            py [b][color=MAROON]([/color][/b]cadr ip[b][color=MAROON])[/color][/b]
            pz [b][color=MAROON]([/color][/b]caddr ip[b][color=MAROON])[/color][/b]
            ra [b][color=MAROON]([/color][/b]/ [b][color=GREEN]([/color][/b]* [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 50 ed[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] 180.0[b][color=GREEN])[/color][/b] pi[b][color=MAROON])[/color][/b]
            an [b][color=MAROON]([/color][/b]entnext en[b][color=MAROON])[/color][/b]
            ad [b][color=MAROON]([/color][/b]entget an[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]/= [color=#2f4f4f]"SEQEND"[/color] [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 0 ad[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq tn [b][color=GREEN]([/color][/b]strcase [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 2 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]cond [b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]= tn [color=#2f4f4f]"ROT"[/color][b][color=BLUE])[/color][/b]
                    [b][color=BLUE]([/color][/b]entmod [b][color=RED]([/color][/b]subst [b][color=PURPLE]([/color][/b]cons 1 [b][color=TEAL]([/color][/b]rtos ra 2 8[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b]
                                   [b][color=PURPLE]([/color][/b]assoc 1 ad[b][color=PURPLE])[/color][/b] ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                   [b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]= tn [color=#2f4f4f]"POS"[/color][b][color=BLUE])[/color][/b]
                    [b][color=BLUE]([/color][/b]entmod [b][color=RED]([/color][/b]subst [b][color=PURPLE]([/color][/b]cons 1 [b][color=TEAL]([/color][/b]strcat [b][color=OLIVE]([/color][/b]rtos px 2 8[b][color=OLIVE])[/color][/b]
                                               [color=#2f4f4f]","[/color] [b][color=OLIVE]([/color][/b]rtos py 2 8[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b]
                                   [b][color=PURPLE]([/color][/b]assoc 1 ad[b][color=PURPLE])[/color][/b] ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq an [b][color=GREEN]([/color][/b]entnext an[b][color=GREEN])[/color][/b]
                   ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

-David

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