HELP WITH LISP

HELP WITH LISP

Anonymous
Not applicable
438 Views
1 Reply
Message 1 of 2

HELP WITH LISP

Anonymous
Not applicable

I wrote a visual lisp file where I can move an entire block using handles and i'm having several issues. First there's a step where i "ssget x" all the objects in one layer and it's not grabbing the all the objects (module and two rails) after the dynamic block is exploded. It only grabs the object that is a block (the module which i assume that is why it is grabbing it).

 

another issue is, in the visibility state dynamic block i created a associative dimension where it measure the distance between the roof (i added a noplot line in the block to associate the dimension as a substitute for the roof) I easily just move the block and place the noplot line over the roof because it will not move. only thing that is moving is the module with the two rails. In my code, I wrote that the module will move from this point to another point. in the code I had to explode the block but some reason it just create a duplicate and of the block and then explodes, so I wrote a code step where it will vla-erase the block and have only the exploded block but that loses the associated dimension from the module to the roof. Help please. Im having difficulties. If someone needs more info, I'm glad to provide. Here is the code below:

 

(defun c:snapRR ()
(vl-load-com)
(setq blocks (vla-get-Blocks(vla-get-ActiveDocument (vlax-get-acad-object))))
(setq myrail(handent "2f2a93"))
(setq myrail2(vlax-ename->vla-object myrail)) ;converts the rail w/ module block to visual lisp properties
(setq myattach(handent "307c0"))
(setq myattach2(vlax-ename->vla-object myattach));converts the attachment block
(vla-explode myattach2)
(vla-erase myattach2)
(vla-explode myrail2)
(vla-erase myrail2)
(setq stptline(ssget "x" '((8 . "noplotr"))));selects all the object in layer noplotr
(setq stptentityname(ssname stptline 0));provides the entity name
(setq stptLINE2(vlax-ename->vla-object stptentityname));converts the object in noplotr to visual lisp prop
(setq startpoint(vla-get-startpoint stptLINE2));retrieves the startpoint of the line in layer noplotr from the property list
(setq stptconvert2(vlax-safearray->list (vlax-variant-value startpoint)));converts the variant to a list
(setq stptconvert3(vlax-3d-point stptconvert2));converts the list of number to 3d point coordinates
(setq attachcoor(ssget "x" '((8 . "noplotA"))));selects all the object in layer noplotA
(setq attachcoor1(ssname attachcoor 0));provides the entity name for the noplotA selection set
(setq attachcoor2(vlax-ename->vla-object attachcoor1));converts the object in layer noplotA to visual lisp prop
(setq getcoor(vla-get-coordinates attachcoor2));grabs the coordinates from the property list
(setq getcoor1(vlax-safearray->list (vlax-variant-value getcoor)));converts variant to list
(setq getcoor2(vlax-3d-point getcoor1));converts the list to a 3d coordinates for movements of blocks
(setq railparts(ssget "x" '((8 . "rails"))));it should select everything in this layer. It only selects the module and not the rails.
(setq railmove(ssname railparts 0));grabs the entity name.
(setq rails(vlax-ename->vla-object railmove));converts it to a visual lisp
(vla-move rails stptconvert3 getcoor2);suppose to move everything in layer "rails" from point stptconvert3 to getcoor2 but it only moves the modules and not rails.; updates any fields based on the movemeent of the rails )
(princ)
)

0 Likes
439 Views
1 Reply
Reply (1)
Message 2 of 2

dbroad
Mentor
Mentor

Welcome to the group.  It's good to see someone working through these items.  One thing that has helped me debug my work is using VLIDE.  In Vlide, you can select and load each line.  This can give you feedback as you build your application.

 

Suggestions:

Never design a program to work with a single object handle.  Just do the work yourself.  To make the program more flexible, use selection sets.

 

Use the return values from the functions.  For example, I believe vla-explode has a return value that contains an array of the objects from the explode operation.

 

Once you explode a block reference, it is deleted from the drawing.  You cannot access it again.  Do not erase it.

 

Never assume a selection finds any objects always test before using a selection set with ssname.

 

As you load each part with vlide, investigate the return values.

Architect, Registered NC, VA, SC, & GA.
0 Likes