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

Need help with inserting block based on reference point

6 REPLIES 6
Reply
Message 1 of 7
pineypl
191 Views, 6 Replies

Need help with inserting block based on reference point

Working on some sewer profiles and need to insert a block based on a reference point. I do want to manipulate the Y coordinate a bit. The block is inserted with an X scale factor of 1 and the Y scaled factor will be calculated with a factor of 10 due to how the profiles are drawn (X axis is 1:1, but Y axis is 1:10). I am having a time getting the basics to work. I can skip the factor of 10 portion and simply do that in my head as I insert the reals of the invert and rim elevations. The following is my code.

[start code]
(defun c:sm ( / BP X Y Z NEWPT INV RIM)
(setq BP (getpoint "Pick point: "))
(setq INV (getreal "Invert elevation:"))
(setq RIM (getreal "Rim elevation:"))
(setq X (car BP)
Y (+ INV (cadr BP))
Z (caddr BP)
)
(setq NEWPT (strcat X Y Z))

(command "-insert" smh NEWPT pause)
)
)
[end code]

When I load the lisp it complains of "error: extra right paren on input"
When I run the lisp I can do the pick point, enter the invert, enter the rim, then it complains of "error: bad argument type: stringp 51.0648". 51.0648 is the X value of the pickpoint or CAR BP.

Basically I want to pick a point to insert the block smh, with a modification to y axis coordinate and a modification to the y scale factor. I need to reference a point that is the centerline of the manhole location. This centerline item will be placed by me based on the manhole spacings we set up in the plans.

The y scale factor would be the Rim Elevation - Invert Elevation.

Thanks for the help.
6 REPLIES 6
Message 2 of 7
Ian_Bryant
in reply to: pineypl

Hi,
to get rid of the loading error
remove the
) on the line before [end code].
As the error message says you have
one too many right parentheses
i.e. too many closing brackets.

The strcat function only works on strings.
X Y & Z are reals.
You dont need to feed a string as base point
of the insert command.
Feed it a point list, i.e. replace
(setq NEWPT (strcat X Y Z))
with
(setq NEWPT (list X Y Z))
Regards Ian
Message 3 of 7
Anonymous
in reply to: pineypl

Also, you want (list) instead of (strcat) to put numbers together into a point. The (strcat)
function is for joining [conCATenating] text STRings together.
--
Kent Cooper


wrote...
Working on some sewer profiles and need to insert a block based on a reference point. I do want to
manipulate the Y coordinate a bit. The block is inserted with an X scale factor of 1 and the Y
scaled factor will be calculated with a factor of 10 due to how the profiles are drawn (X axis is
1:1, but Y axis is 1:10). I am having a time getting the basics to work. I can skip the factor of 10
portion and simply do that in my head as I insert the reals of the invert and rim elevations. The
following is my code.

[start code]
(defun c:sm ( / BP X Y Z NEWPT INV RIM)
(setq BP (getpoint "Pick point: "))
(setq INV (getreal "Invert elevation:"))
(setq RIM (getreal "Rim elevation:"))
(setq X (car BP)
Y (+ INV (cadr BP))
Z (caddr BP)
)
(setq NEWPT (strcat X Y Z))

(command "-insert" smh NEWPT pause)
)
)
[end code]

When I load the lisp it complains of "error: extra right paren on input"
When I run the lisp I can do the pick point, enter the invert, enter the rim, then it complains of
"error: bad argument type: stringp 51.0648". 51.0648 is the X value of the pickpoint or CAR BP.

Basically I want to pick a point to insert the block smh, with a modification to y axis coordinate
and a modification to the y scale factor. I need to reference a point that is the centerline of the
manhole location. This centerline item will be placed by me based on the manhole spacings we set up
in the plans.

The y scale factor would be the Rim Elevation - Invert Elevation.

Thanks for the help.
Message 4 of 7
pineypl
in reply to: pineypl

Thank you both, Ian and Kent. That was a big help in getting this to function. Yes, the string was breaking me. I added a couple of things and it is working perfectly. Here is the code with all updates at this point in time. I am sure I will add some more error checking and the like.

[start code]
(defun c:sm (/ BP X Y Z NEWPT INV RIM YS)
(setvar "osmode" 1)
(setq BP (getpoint "\nPick point: "))
(setvar "osmode" 0)
(setq INV (getreal "\nInvert elevation:"))
(setq RIM (getreal "\nRim elevation:"))
(setq X (car BP)
Y (+ INV (cadr BP))
Z (caddr BP)
)
(setq NEWPT (list X Y Z))
(setq YS (- RIM INV))
(command "-insert" "smh" NEWPT "" YS "")
)
[end code]
Message 5 of 7
Anonymous
in reply to: pineypl

Here's another trick you can use. The (mapcar) function can do things like add together the
corresponding elements of two lists, so you can make your NEWPT by adding BP to a virtual "point"
with INV for its Y component, and zero for the others. That way, you don't need to extract the
elements of your BP value, add to one of them, and then put them back together. You could replace
this much:

(setq X (car BP)
Y (+ INV (cadr BP))
Z (caddr BP)
)
(setq NEWPT (list X Y Z))

with just this:

(setq NEWPT (mapcar '+ BP (list 0 INV 0)))

and eliminate the X Y Z from the local variables list.

--
Kent Cooper


wrote...
Thank you both, Ian and Kent. That was a big help in getting this to function. Yes, the string was
breaking me. I added a couple of things and it is working perfectly. Here is the code with all
updates at this point in time. I am sure I will add some more error checking and the like.

[start code]
(defun c:sm (/ BP X Y Z NEWPT INV RIM YS)
(setvar "osmode" 1)
(setq BP (getpoint "\nPick point: "))
(setvar "osmode" 0)
(setq INV (getreal "\nInvert elevation:"))
(setq RIM (getreal "\nRim elevation:"))
(setq X (car BP)
Y (+ INV (cadr BP))
Z (caddr BP)
)
(setq NEWPT (list X Y Z))
(setq YS (- RIM INV))
(command "-insert" "smh" NEWPT "" YS "")
)
[end code]
Message 6 of 7
pineypl
in reply to: pineypl

Thanks, Kent.

That looks really clean and efficient, I shall try it. Thanks.

I have been using the last round of code for a couple of hours and it more than makes up for my lost time yesterday trying to properly build the lisp.

Thanks again!
Bob
Message 7 of 7
Anonymous
in reply to: pineypl

That's just what this group is here for -- I'm glad it worked.
--
Kent Cooper


wrote...
Thanks, Kent.

That looks really clean and efficient, I shall try it. Thanks.

I have been using the last round of code for a couple of hours and it more than makes up for my lost
time yesterday trying to properly build the lisp.

Thanks again!
Bob

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

Post to forums  

Autodesk Design & Make Report

”Boost