Author Topic: Mass Move Blocks to Nearest Line  (Read 1870 times)

0 Members and 1 Guest are viewing this topic.

Ohnoto

  • Guest
Mass Move Blocks to Nearest Line
« on: March 09, 2016, 04:06:33 PM »
I have had this code written for several years, and used functionally for a variety of aspects. The basics of the code is that it inserts blocks into a drawing based on node points and rotate blocks based on number in the syntax, but to be perpendicular to a line. All of that portion works.

Now, I am trying to expand the code to move certain blocks to the nearest line. In the syntax, there is a 0 or 1 for this parameter. Those blocks with a 1 need to be moved.

I have been able to get the LISP to work, but only for one node. If there are multiple nodes, bad things happen. I've attached the current code, as it is rather long, and a test drawing.

Essentially, what is going on is that when there are multiple nodes, it is placing the first one correctly. Then it is placing, followed up with deleting, following blocks. When putting in a different type of block, for what we use for light representation, it is get stretched ALOT.

Any help in getting these function to work out properly is appreciated.

roy_043

  • Water Moccasin
  • Posts: 1893
  • BricsCAD 18
Re: Mass Move Blocks to Nearest Line
« Reply #1 on: March 10, 2016, 08:45:45 AM »
The error is due to the use of the same cnt range (0-2) to access a selection set with 3 entities (pointSet) and a set with only 1 entity (BLINSBaselineSet).

Ohnoto

  • Guest
Re: Mass Move Blocks to Nearest Line
« Reply #2 on: March 10, 2016, 11:43:46 AM »
I put in a different count variable for obtaining the nearest point.

Code: [Select]
  (if BLINSBaselineSet
    (progn
      (setq count 0)
      (while (< count (sslength BLINSBaselineSet))        ; WHILE the length of the set (pointSet) is less than the counter (cnt)
(setq enamed (ssname BLINSBaselineSet count))        ; use the SSName function to assign the value from the counter to the (pointSet) variable
(setq nearpt (vlax-curve-getClosestPointTo enamed pt))   ; declare the point (pt) variable
(setq count (+ count 1))
)
      )
    )

Though, now it is erasing all 3, and not moving any of them to the nearest line. The light block is still coming in extremely stretched.

Ultimately, this will be used on a larger scale with many other blocks and more wall lines. It's just getting it to move the block to the nearest wall line while.

I am pretty stumped at this point. Get the insert point, get the nearest point, get the angle, insert the block, select the block and move to the nearest point, adjust the count and start with the next node. That's been the mindset so far on this, just not sure exactly what the breakdown is... admittedly, this week is the first time in about 2 years that I have put quite a bit of time into LISP.

ronjonp

  • Needs a day job
  • Posts: 7423
Re: Mass Move Blocks to Nearest Line
« Reply #3 on: March 10, 2016, 12:46:01 PM »
Did not look at your code but quick pseudo code based on the thread title:

1. Grab all blocks
2. Grab all lines
3. Cycle through blocks using insertionpoint & vlax-curve-getclosestpointto all of your lines
4. Sort to find closest item to move block to
5. Move block
6. Repeat

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

roy_043

  • Water Moccasin
  • Posts: 1893
  • BricsCAD 18
Re: Mass Move Blocks to Nearest Line
« Reply #4 on: March 10, 2016, 01:01:48 PM »
... To correct the scaling of the blocks you should revise the arguments you supply to the -INSERT command. This should not be a problem.

Ohnoto

  • Guest
Re: Mass Move Blocks to Nearest Line
« Reply #5 on: March 10, 2016, 02:09:30 PM »
Looking like a separate LISP may be the easier route to go with this. I've modified and old LISP found at, http://www.arch-pub.com/Move-point-perpendicular-to-line_10272335.html.

This isn't moving the objects to the nearest line, but one that is far away from the points, and stacking all of the blocks onto the same spot.

Code: [Select]
(defun c:snapToObj ( / en obj pts_ss ss_len c pten ptobj pted pt pt2)
 
  (setq en (ssget "_X" (list
(cons 0 "ARC,CIRCLE,ELLIPSE,LINE,LWPOLYLINE,POLYLINE,SPLINE")
(cons 8 "A-WALL-INTR")
))
)

  (princ "\nSelect Blocks: ")
  (setq pts_ss (ssget (list (cons 0 "INSERT"))))
 
(setq ss_len (sslength pts_ss))
 
(setq c 0)
  (while (< c ss_len)
    (setq pten (ssname pts_ss c))
    (setq ptobj (vlax-ename->vla-object pten))
    (setq pted (entget pten))
    (setq pt (cdr (assoc 10 pted)))

    (setq cnt 0)
(while (< cnt (sslength en))
  (setq ename (ssname en cnt))
  (setq pt2 (vlax-curve-getClosestPointTo ename pt))
  (setq cnt (+ cnt 1))
  )
 
    (vla-move ptobj (vlax-3d-point pt) (vlax-3d-point pt2))
    (setq c (+ c 1))
    )
 
(princ)
 
)


roy_043

  • Water Moccasin
  • Posts: 1893
  • BricsCAD 18
Re: Mass Move Blocks to Nearest Line
« Reply #6 on: March 11, 2016, 03:21:00 AM »
You should read Ron's pseudo code again. At no point in your code are you comparing distances.
Analysing the code in this post (also by ronjonp) will be useful I think:
https://www.theswamp.org/index.php?topic=50994.msg561876#msg561876