Jump to content

Insert Block, Angle and Move to nearest Line


Ohnoto

Recommended Posts

I'm working on this LISP that inserts blocks based on node points and then rotates the inserted block towards the nearest line based on layer. For select blocks, will also move the block to the nearest point.

 

I've attached the full LISP, because it is a longer LISP file. Below are more specific areas of noting.

 

Currently, I'm getting an error of "Command: BLI ; error: bad argument type: lselsetp nil".

 

The insert block based on the node point is what we have had, and currently works as intended.

 

Syntax

 

;;; --------- SYNTAX -    "layer of pt"       "block name"                     "layer for block"    "visb for blck"              "Angle"    "Adjust Insert"
(BLINS_BlockFunction     "E-LITE-CLNG"        "Ceiling Lights"                 "E-LITE-CLNG"        "Ceiling Light - Recessed"   nil        0)
(BLINS_BlockFunction     "T-SOUN-FLOR"        "FE Outlet-Duplex-Wall v7.0"     "E-POWR-FLOR"        ""                           0          1)

 

Main Funtion

 

Within the BLINS_BlockFunction, the part that I am adding with the angle and closest point. If the "Adjust Insert" is 0, then it won't move to the nearest wall line. If it is 1, then it will move. Not all blocks are expected to move to the nearest wall line.

 

(defun BLINS_BlockFunction (myBLILayer myBlockName myBlockLayer myVisibility myAA AIns)
...

(setq pt (cdr (assoc 10 enlist)))	; declare the point (pt) variable
(setq myAngle (BLINS_GetAngle pt myAA)) ; set angle of block insertion.
(if (= AIns 0)	;If Adjust Insert = 0, then keep closestpt the same as insertion point.
    (setq closestpt pt))
(if (= AIns 1)  ;If Adjust Insert = 1, then set closestpt to nearest wall line.
    (setq closestpt myPointTMP))	;myPointTMP is set in the BLINS_GetAngle function.

(command "_-insert" myBlockName closestpt 1 myAngle "")

...

 

Determining the Angle

With an earlier version of the code, prior to the error I started getting, it would insert the block at 180 degrees, plus the specified angle noted in the syntax. Even if there was an odd angled wall line near the insertion point.

 

What is expected is that it determines the angle to the line, and then adds the angle from the syntax. The reason for this is to make sure the block comes in perpendicular to the line.

 

(defun BLINS_GetAngle (myPoint myAA / myPoint2 myPointTMP myDistTMP myDist cnt enlist myAngle)
;;; Get Angle Based on Closest Point To Baseline Set
(if 
	(progn
		(setq cnt 0)
		(while (< cnt (sslength BLINSBaselineSet))       ; WHILE the length of the set (pointSet) is less than the counter (cnt)
			(setq ename (ssname BLINSBaselineSet cnt))        ; use the SSName function to assign the value from the counter to the (pointSet) variable
			(setq myPointTMP (vlax-curve-getClosestPointTo ename myPoint ))       ; declare the point (pt) variable
			(setq myDistTMP (distance myPoint myPointTMP))
			(if (or (= myDist nil) (< myDistTMP myDist))
				(progn
					(setq myDist myDistTMP)
					(setq myPoint2 myPointTMP))
				) ;end if (or (= myDist nil) (< myDistTMP myDist))
			(setq cnt (+ cnt 1))
			);end while
		(setq myAngle (Angle_RTD (angle myPoint myPoint2))) ; "angle" Return Values == An angle, in radians.
		) ;end progn
	(setq myAngle 180) ;if (else)
	) ;end if

(if (/= myAA nil)
  (setq myAngle (+ myAngle myAA)))
myAngle
) ;defun BLINS_GetAngle


(defun Angle_RTD (anglertd)
(/ (* anglertd 180.0) pi))

 

Within part of that, it is prompting for the baseline of the line. That part is:

 

(defun BLINS_CreateBaselineSet ()
  (setq BLINSBaselineSet
			 (ssget "_X" (list
					(cons 0 "ARC,CIRCLE,ELLIPSE,LINE,LWPOLYLINE,POLYLINE,SPLINE")
					(cons 8 "A-WALL-INTR")
					)))
 );defun BLINS_CreateBaselineSet

 

 

Thanks for any assistance that can be provided.

BLINS_Main - 0008.LSP

Link to comment
Share on other sites

I got the angle portion working, and if AINS variable is set to 0.

 

Now, it is down to the portion of if AINS variable is set to 1, that it would move to the nearest point based on the baseline. This could either be done by moving the block after insertion or the node point prior to insertion. I've been trying different ways to get it to work.

Link to comment
Share on other sites

I've been attempting something along the lines of the code below, to no avail.

 

                     (if (= AIns 1)    ;If Adjust Insert = 1, move node to location of nearest wall line.
                         ((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 cnt))        ; use the SSName function to assign the value from the counter to the (pointSet) variable
                             (setq nearpt (vlax-curve-getClosestPointTo enamed myPoint))           ; declare the point (pt) variable
                             (setq count (+ count 1))
                             );end while
                           );end progn
                         )
                     (vla-move epoint pt nearpt)
                     (setq closestpt nearpt)
                     ))

 

Trying to get the nearest location from the node to the line selection set. Then moving the node from the location spot to that nearest point.

 

I've been getting errors of: "bad argument type: VLA-OBJECT" or "bad argument type: 2D/3D point: nil"

Link to comment
Share on other sites

I've gotten this LISP close to done. Working with one node point, I got it to work, thought it was done. Then when testing with more node points, getting... undesirable results.

 

I put in 3 of the same type of node for block to insert on. First one came in perfect. Second one appears, but then is deleted. The third never appears. I also put in a node for a ceiling light block, that the location of won't be adjusted. The block comes in extremely stretched for some odd reason.

 

I've attached a sample drawing and update of current LISP.

BLI Test.dwg

BLINS_Main - 0015.LSP

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...