Author Topic: BoundingBox with shifting of Points  (Read 2882 times)

0 Members and 1 Guest are viewing this topic.

ChrisCarlson

  • Guest
BoundingBox with shifting of Points
« on: August 20, 2014, 05:12:17 PM »
Code: [Select]
    (progn
      (vla-getboundingbox (vlax-ename->vla-object (ssname (ssget "_L") 0)) 'Point1 'Point2)
      (setq Point2 (vlax-safearray->list Point2))
  (setq X (car Point2))
  (setq Y (cadr Point2))
  (setq hrevid_locX (+ 0.11 X))
  (setq hrevid_locY (+ -0.22 Y))
  (setq hrevid_loc (strcat (rtos hrevid_locX 2 2)","(rtos hrevid_locY 2 2)",0"))
)

I'm attempting to list the coordinates of an object, perform some math and pass the new coordinate to my insert command. However the new location seems sporadic and doesn't quite make sense to me.

X needs to move +0.11 (right .11 units)
Y needs to move -0.22 (down .22 units)



As you can see it appears it's combining the math of the X value and the match of the Y value...or making stuff up!

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: BoundingBox with shifting of Points
« Reply #1 on: August 20, 2014, 06:35:01 PM »
What code are you using to insert the block?
Have you accounted for Object Snap? (i.e. by preceding point input with "_non")

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: BoundingBox with shifting of Points
« Reply #2 on: August 20, 2014, 06:37:09 PM »
Here's another way to write the code:

Code: [Select]
(if (setq sel (ssget "_L"))
    (progn
        (vla-getboundingbox (vlax-ename->vla-object (ssname sel 0)) 'llp 'urp)
        (command "_.-insert" "<YourBlockName>" "_S" 1.0 "_R" 0.0 "_non" (mapcar '+ (vlax-safearray->list urp) '(0.11 -0.22)))
    )
    (princ "\nNo last object.")
)

ChrisCarlson

  • Guest
Re: BoundingBox with shifting of Points
« Reply #3 on: August 21, 2014, 07:37:28 AM »
I was unaware of the "_non" command, actually seems like it solves a few of my other problems I had.

Why does current object snap mode affect the placement of a block/object if I issue exact coordinates?

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: BoundingBox with shifting of Points
« Reply #4 on: August 21, 2014, 09:21:34 AM »
I was unaware of the "_non" command, actually seems like it solves a few of my other problems I had.

Not so much a command in itself, just another Object Snap modifier (like "_end" or "_mid" or "_nea" etc.)
"_non" or "_none" may be used.

Why does current object snap mode affect the placement of a block/object if I issue exact coordinates?

I would hazard a guess that the points are interpreted by the command as if the user had picked the coordinates on screen - though I'm not entirely aware of the inner workings of how coordinates are interpreted by the command function.

cmwade77

  • Swamp Rat
  • Posts: 1449
Re: BoundingBox with shifting of Points
« Reply #5 on: August 22, 2014, 07:53:47 PM »
I would hazard a guess that the points are interpreted by the command as if the user had picked the coordinates on screen - though I'm not entirely aware of the inner workings of how coordinates are interpreted by the command function.

This is exactly what happens, I actually get the OSNAP variable value, set it to 0 while running my commands, then reset it when finished.

Chris,

It looks like you are trying to do something that I have been trying to do with my Revcloud command for a while. If you would be kind enough to share your entire code, I would love to take a look, maybe we can help each other on this one.

ChrisCarlson

  • Guest
Re: BoundingBox with shifting of Points
« Reply #6 on: August 22, 2014, 09:16:10 PM »
With the OSNAP setting, is it good practice to set to 0 and set back? I have a few other routines to write which relies on exact coordinates.  I just find it weird if I set where to put an object to the millionth of an inch, AutoCAD thinks I want it somewhere else :furious:

I won't have any access until Monday but whatcha stuck on? Make a new thread and I can reply with a few snippets off the top my head

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: BoundingBox with shifting of Points
« Reply #7 on: August 22, 2014, 09:41:47 PM »
< .. >  I just find it weird if I set where to put an object to the millionth of an inch, AutoCAD thinks I want it somewhere else :furious:



This is happening because you are using a 'command' paradigm and the currently active osnap settings are enforced, as designed.
If you want to resolve the issue you have several options:
  • Save the current osnap settings , set osnap to 0 , run your command , reset the osnap to the previously saved settings.
  • Use  "_non" or "_none" as mentioned.
  • Use ActiveX or entmake tour objects so the osnap settings are ignored.
  • Use any language that modifies the database directly
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: BoundingBox with shifting of Points
« Reply #8 on: August 23, 2014, 04:55:00 AM »
With the OSNAP setting, is it good practice to set to 0 and set back? I have a few other routines to write which relies on exact coordinates.  I just find it weird if I set where to put an object to the millionth of an inch, AutoCAD thinks I want it somewhere else :furious:

You can get rid of this problem once and for all.
Set system variable OSNAPCOORD to 1 or: