Trying to correct dynamic block positions with calculated coordinates

Trying to correct dynamic block positions with calculated coordinates

Gorra
Advocate Advocate
771 Views
8 Replies
Message 1 of 9

Trying to correct dynamic block positions with calculated coordinates

Gorra
Advocate
Advocate

Hello,

I'm hoping this is a silly question. I'm trying to correct the position of a dynamic block using calculated coordinates. Preferably not using the move command as that adds a layer of potential error.

This would be easy with a non-dynamic block, I just used (setpropertyvalue "Position/X" Northing) and it worked fine. I tried using LeeMac's (LM:setdynpropvalue) which works for the rest of the properties, but not with "Position/X" or "Insertion point X", which are what shows up when I do a dump of the block.

 

Failing that, I know a block can be temporarily treated as a dynamic block with (vlax-ename->vla-object a), can a dynamic block be temporarily treated as a regular one for one command? 

 

The subfunction is here:

 
  (defun FixSplcCs (blk / GripDist_X GripDist_Y OldAnno_X NewAnno_X OldAnno_Y NewAnno_Y TrgIns_X TrgIns_Y)
(setq GripDist_X (LM:getdynpropvalue blk "SPLICE GRIP X"))
(setq GripDist_Y (LM:getdynpropvalue blk "SPLICE GRIP Y"))
(if (or 
    (/= GripDist_X 0)
(/= GripDist_Y 0)) ; if either case grip point is non-zero
(progn  ; then correct block position
(setq Insert_X Northing)
(setq Insert_Y Easting)
(setq OldAnno_X (LM:getdynpropvalue blk "SPLICE#/MODEL GRIP X"))
(setq OldAnno_Y (LM:getdynpropvalue blk "SPLICE#/MODEL GRIP Y"))
(setq TrgIns_X (+ Insert_X GripDist_X))
(setq TrgIns_Y (+ Insert_Y GripDist_Y))
(setq NewAnno_X (- OldAnno_X GripDist_X))
(setq NewAnno_Y (- OldAnno_Y GripDist_Y))
(LM:setdynpropvalue blk "Position/X" TrgIns_X)  ;;<-- These two lines are the only ones not working. No error 
(LM:setdynpropvalue blk "Position/Y" TrgIns_y)  ;;<--   message, they just don't do anything
(LM:setdynpropvalue blk "SPLICE GRIP X" 0)
(LM:setdynpropvalue blk "SPLICE GRIP Y" 0)
(LM:setdynpropvalue blk "SPLICE#/MODEL GRIP X" NewAnno_X)
(LM:setdynpropvalue blk "SPLICE#/MODEL GRIP Y" NewAnno_Y)
(setq Northing TrgIns_X)
(setq Easting TrgIns_Y)
) ; end progn true
; (progn
; (setq Northing (getpropertyvalue blk "Position/X"))
; (setq Easting (getpropertyvalue blk "Position/Y"))
; ) ; end progn false
) ; end if
  )

 

The full LISP is attached but is rather large. Thanks for any pointers.

0 Likes
Accepted solutions (1)
772 Views
8 Replies
Replies (8)
Message 2 of 9

CodeDing
Advisor
Advisor

@Gorra ,

 

You can set the position of a Dynamic Block using the same "Position/X" & "Position/Y" methods.

As seen here:

db_move.gif

 

So, something else must be going wrong with your lisp.

Most people struggle with troubleshooting WHAT the ACTUAL problem IS. (That's the hardest part is finding it)

If it says something like:

"; error: bad argument type: numberp: nil"

Then, that means one of your variables is likely set to "nil" accidentally and a function using that variable expected it to be a number. You will have to find the definition(s) of that variable and test where it could be going wrong.

 

What does your command history say when you run your command?

0 Likes
Message 3 of 9

CodeDing
Advisor
Advisor

What happens when you run your code while using the "setpropertyvalue" functions?

 

(defun FixSplcCs (blk / GripDist_X GripDist_Y OldAnno_X NewAnno_X OldAnno_Y NewAnno_Y TrgIns_X TrgIns_Y)
  (setq GripDist_X (LM:getdynpropvalue blk "SPLICE GRIP X"))
  (setq GripDist_Y (LM:getdynpropvalue blk "SPLICE GRIP Y"))
  (if (or (/= GripDist_X 0)
          (/= GripDist_Y 0)) ; if either case grip point is non-zero
    (progn  ; then correct block position
      (setq Insert_X Northing)
      (setq Insert_Y Easting)
      (setq OldAnno_X (LM:getdynpropvalue blk "SPLICE#/MODEL GRIP X"))
      (setq OldAnno_Y (LM:getdynpropvalue blk "SPLICE#/MODEL GRIP Y"))
      (setq TrgIns_X (+ Insert_X GripDist_X))
      (setq TrgIns_Y (+ Insert_Y GripDist_Y))
      (setq NewAnno_X (- OldAnno_X GripDist_X))
      (setq NewAnno_Y (- OldAnno_Y GripDist_Y))
      (setpropertyvalue blk "Position/X" TrgIns_X)
      (setpropertyvalue blk "Position/Y" TrgIns_y)
      (LM:setdynpropvalue blk "SPLICE GRIP X" 0)
      (LM:setdynpropvalue blk "SPLICE GRIP Y" 0)
      (LM:setdynpropvalue blk "SPLICE#/MODEL GRIP X" NewAnno_X)
      (LM:setdynpropvalue blk "SPLICE#/MODEL GRIP Y" NewAnno_Y)
      (setq Northing TrgIns_X)
      (setq Easting TrgIns_Y)
    );progn
  ;else
    (progn
      (setq Northing (getpropertyvalue blk "Position/X"))
      (setq Easting (getpropertyvalue blk "Position/Y"))
    );progn
  );if
);defun
0 Likes
Message 4 of 9

Gorra
Advocate
Advocate

@CodeDing 

 

When I use (setpropertyvalue blk "Position/X" TrgIns_X) I get 

 

Command: ; error: invalid data type or data overflow: #<VLA-OBJECT IAcadBlockReference 000002025e981348>

 

When I use (LM:setdynpropvalue blk "Position/X" TrgIns_X), I don't get an error, but it doesn't do anything.

0 Likes
Message 5 of 9

CodeDing
Advisor
Advisor
Accepted solution

When I use (setpropertyvalue blk "Position/X" TrgIns_X) I get 

 

Command: ; error: invalid data type or data overflow: #<VLA-OBJECT IAcadBlockReference 000002025e981348>


This means you are trying to pass an ActiveX entity name when you should be trying to pass an AutoLISP entity name.

Try this fix:

 

(setq blkTemp (vlax-vla-object->ename blk))
(setpropertyvalue blkTemp "Position/X" TrgIns_X)
(setpropertyvalue blkTemp "Position/Y" TrgIns_y)

 

0 Likes
Message 6 of 9

Gorra
Advocate
Advocate

@CodeDing 

 

Thank you once again, that was the final glitch in the process. 

 

Gorra

Message 7 of 9

Amriya_Exe
Advocate
Advocate
I need help something like this.
My dynamic block have 9 points to move on marked coordinate for final result.
It's possible to adjust them using lisp?
I have coordinates in excel.
0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor

You asked this somewhere else.

 

Can you post an image or dwg of your dynamic block may be easier just draw it.

0 Likes