Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trying to correct dynamic block positions with calculated coordinates

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Gorra
539 Views, 8 Replies

Trying to correct dynamic block positions with calculated coordinates

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.

8 REPLIES 8
Message 2 of 9
CodeDing
in reply to: Gorra

@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?


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 3 of 9
CodeDing
in reply to: Gorra

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

Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 4 of 9
Gorra
in reply to: CodeDing

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

Message 5 of 9
CodeDing
in reply to: Gorra


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)

 


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 6 of 9
Gorra
in reply to: CodeDing

@CodeDing 

 

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

 

Gorra

Message 7 of 9
Amriya_Exe
in reply to: CodeDing

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.
Message 8 of 9
Sea-Haven
in reply to: Gorra

You asked this somewhere else.

 

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

Message 9 of 9
Amriya_Exe
in reply to: Sea-Haven

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report