Author Topic: Lisp results based on external data  (Read 8434 times)

0 Members and 2 Guests are viewing this topic.

MGEE

  • Guest
Lisp results based on external data
« on: November 17, 2003, 08:55:37 AM »
I would like to generate a pline rectangle, extrude it, and attach 4 nodes or pipe nipples to one side at specific points (of course). And each L,W,& H would be pulled from an XL sheet. ??Shoot me or wound me?
If I could get to this point in understanding Lisp, I could automate a tremendous amount of my daily duties.
Thanks for any insight.
MGEE

Edited:
Also I've made a custom Menu with my personal buttons and saved it as custom_MG but I have to load it each time I start up Acad.How do you make it load automatically?
Thanks MGEE


7Edit: I renamed this topic.

Eloquintet

  • Gator
  • Posts: 3206
Lisp results based on external data
« Reply #1 on: November 17, 2003, 09:08:48 AM »
ummm as far as the second part of your question you may wanna read the recent loading custom menus topic. did you put the directory in autocads search path? if you don't know go to tools/options/files and add the folder where your menu is stored. see i'm learning guys  :lol:

dan
Dan

AutoCAD Architecture 2015

Mark

  • Custom Title
  • Seagull
  • Posts: 28685
Lisp results based on external data
« Reply #2 on: November 17, 2003, 09:09:19 AM »
In The Visual LISP Developers Bible 2003 Edition By David M. Stein there is a chapter (21) on working with Excel, with examples.

As far as the menu goes, perhaps you could upload your .mns file to the lilly pond for us to look at.

http://theswamp.org/lilly.pond/
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Lisp results based on external data
« Reply #3 on: November 17, 2003, 09:13:26 AM »
Oh dear .. you need to read from Excel? What weapon would you prefer??

You know, some ppl would cut in here and recommend that you use VBA for these kinds of tasks. I would too, but of course it is possible to do from AutoLISP.

What version of Acad are you running? Should we assume that Excel is open when doing yer thing or should it be opened by AutoCAD? Would you like the fullblown type library solution or an anonymous solution?

SMadsen

  • Guest
Lisp results based on external data
« Reply #4 on: November 17, 2003, 09:14:14 AM »
Ah yes, read Dave's Bible first. Excellent!

daron

  • Guest
Lisp results based on external data
« Reply #5 on: November 17, 2003, 09:47:54 AM »
Am I missing something, guys? I see no reference in the opening thread on using excel for anything.

SMadsen

  • Guest
Re: Lisp results based on external data
« Reply #6 on: November 17, 2003, 09:53:22 AM »
Quote from: MGEE
And each L,W,& H would be pulled from an XL sheet. ??


^ ? .. and it did say "external data" (now it does at least)

daron

  • Guest
Lisp results based on external data
« Reply #7 on: November 17, 2003, 10:07:19 AM »
You know? I read that 3 or 4 times and never saw it.

Mark

  • Custom Title
  • Seagull
  • Posts: 28685
Lisp results based on external data
« Reply #8 on: November 17, 2003, 10:10:47 AM »
Quote from: Daron
You know? I read that 3 or 4 times and never saw it.

It is Monday Daron, I can tell becuase of my CDATE question!
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
Lisp results based on external data
« Reply #9 on: November 17, 2003, 10:17:48 AM »
Okay! I'll go home now.

Eloquintet

  • Gator
  • Posts: 3206
Lisp results based on external data
« Reply #10 on: November 17, 2003, 10:20:37 AM »
daron probably looks very similar to ren right about now

dan
Dan

AutoCAD Architecture 2015

hendie

  • Guest
Lisp results based on external data
« Reply #11 on: November 17, 2003, 10:21:29 AM »
If I'm communicating externally from Acad with anything I go the VBA way. But like Stig mentioned, it is possible either way. I suppose it all depends upon how much programming knowledge you have and personal preference
Do you have any VBA or (V)Lisp experience ?

daron

  • Guest
Lisp results based on external data
« Reply #12 on: November 17, 2003, 10:39:22 AM »
Quote from: eloquintet
daron probably looks very similar to ren right about now

dan


minus the pink-eye.

MGEE

  • Guest
Lisp results based on external data
« Reply #13 on: November 17, 2003, 11:08:45 AM »
Don't have any VBA or VLisp knowledge.
On the other matter, I can & did build a custom menu but I have to load it myself every time I start ACAD.

Sorry I'm running Acad 2002

hendie

  • Guest
Lisp results based on external data
« Reply #14 on: November 17, 2003, 11:16:27 AM »
Is there any reason you are drawing a rectangle using a pline then extruding it as opposed to creating a 3d solid (box) ?

MGEE

  • Guest
Lisp results based on external data
« Reply #15 on: November 17, 2003, 11:53:06 AM »
Nope. I guess I need to put my thinking cap on & get this thing fine tuned to the quickest, easiest method to get my end result.
Do you know of a way to link several commands together? Maybe that could be a step in another dirction but better than manually drawing the whole thing?
Thanks

daron

  • Guest
Lisp results based on external data
« Reply #16 on: November 17, 2003, 03:38:31 PM »
Quote from: MGEE
Do you know of a way to link several commands together?

I think that would be called putting user-defined functions into a main function.

Guest

  • Guest
Lisp results based on external data
« Reply #17 on: November 17, 2003, 10:57:03 PM »
Making the rectangular box (is this a tank or reservoir) is
 easy. Extracting the data from excel is the hard part. Have
 you search for 3D routines that does similar things that you
 want either at Cadalog.com or Caddepot.com. I think iHave
 seen some demo that creates ANSI flanges.

hendie

  • Guest
Lisp results based on external data
« Reply #18 on: November 18, 2003, 03:50:48 AM »
Quote from: MGEE
I guess I need to put my thinking cap on & get this thing fine tuned to the quickest, easiest method to get my end result.


you mentioned that the data for the nipples (down Dent) was in an XLS spreadsheet. If you had the "box" data in there as well, you could draw the whole thing in one go.
How is your data formatted ? I mean, exactly what data do you store in respect to the nipples ? ~ diameters, lengths  ~ how are they positioned ? relative to the box ?

MGEE

  • Guest
Lisp results based on external data
« Reply #19 on: November 18, 2003, 08:49:11 AM »
In a cell would be say from insertion point, (25"X,112"Y)
There would be a diameter and length. (4.5"diax6"l) for the size of the nipple. And the box is actually representing an Evaporative Condenser. I would have 2 or 3 Fans on one side say the 0 direction and the connections nipples on the 270 direction. If I can get code to place the nipples, then I think I can expand on it to cut the holes for the fans. And then add an insert of a block that is linked to the XLS which would be the Fan & Grill.
How can I post a pic of one?

hendie

  • Guest
Lisp results based on external data
« Reply #20 on: November 18, 2003, 09:01:31 AM »
Quote from: MGEE
How can I post a pic of one?

see over here

SMadsen

  • Guest
Lisp results based on external data
« Reply #21 on: November 18, 2003, 09:16:15 AM »
Quote from: hendie
... the data for the nipples (down Dent) ...

Funny coincidence, there's also a guy on this forum called Dent  :lol:

MGEE

  • Guest
Lisp results based on external data
« Reply #22 on: November 18, 2003, 10:24:35 AM »
O.K. I posted a pic in the Lilly pond.

daron

  • Guest
Lisp results based on external data
« Reply #23 on: November 18, 2003, 10:39:42 AM »
And the next thing you should do, since we really don't want to make everybody hunt it down is to copy the link and post it, like this [url]http://theswamp.org/lilly.pond/MGEE/EVAP.JPG[/url] or use [img][/img]

MGEE

  • Guest
Lisp results based on external data
« Reply #24 on: November 18, 2003, 10:48:16 AM »
Appologies to all, as you can tell I'm new to posting img's.[/url]

hendie

  • Guest
Lisp results based on external data
« Reply #25 on: November 18, 2003, 10:55:54 AM »
ah, glad to see someone esle is watching this topic as well.

Q: do you have access to Access ? (if you see what I mean !)
the reason I ask is because I've never used Vlisp to connect to a spreadsheet but I have connected through VBA to an MDB file.

Now, if it were me  :shock:  I'd do it the following way:
Have all the info (Box length, width depth etc + all cylinderinfo) stored in Access and just run a query to pull the data from Access and create the whole shebang in one go. Or you could do it all via a dialogue box...

you mentioned that you have the info in a spreadsheet...
Quote
In a cell would be say from insertion point, (25"X,112"Y)

what insertion point ? is that relative to the origin of the box ? or an absolute coordinate ?
Is the nipple a cylinder a tube or a revolved solid ? Are there always the same number of fans / nipples / whatever ?

what we really need form you is some pseudo code detailing exactly the steps you need to take to complete one of these thingamajiggies
i.e.
prompt user for box dimensions
create box
prompt for face to add nipples to
add nipples
prompt for face to add fans to
add fans
etc etc

also, what version of Acad, Excel, Acces do you have ? it all makes a difference

daron

  • Guest
Lisp results based on external data
« Reply #26 on: November 18, 2003, 11:10:31 AM »
Quote from: MGEE
Appologies to all, as you can tell I'm new to posting img's.[/url]
It's okay. Everybody needs to be taught eventually.

MGEE

  • Guest
Lisp results based on external data
« Reply #27 on: November 18, 2003, 11:21:34 AM »
hendie or Daron,
I once heard of a program that recorded your every move. As your talkin about giving you. What's your thoughts on this? Saposidly, it wrote a lisp routine of your footprints? I can actually give you a rundown buy drawing one and then cut & paste the text window. would that be good enough?
Also, I'd like to have the ONE user input option to select the Model of this thingamajiggie cause there are several, and it's insertion point. Which would be the refference for the rest of the entities to be generated by the VBA routine.

hendie

  • Guest
Lisp results based on external data
« Reply #28 on: November 18, 2003, 11:39:54 AM »
ooohh time is tihgt and I'm just about to finish here and I'm on holiday tomorrow...

I think you might be missing the point slightly here.
What you have to consider is how many variables there are.. by that I mean, is the box always the same size ? are there always the same number of nipples ? are they always the same diameter, same number of fans etc.... ad infinitum...
If you want to write code to take care of this function for you , you have to consider taking all the variables into account. It's no good designing a programme to create a box with three nipples when you want to draw a box with 2 or 4 ! see wot I mean ?
One major problem here is that you know what you need to draw ~we don't know unless you tell us.
The best person to answer this question is you.... consider what you want to achieve.... now how do you want to achieve that target... think carefully !

my interpretation of what you have told us so far is something along the lines of...
create a box
add (up to 3 {or more}) nipple extrusions
add (some number of) fans

Now, I would probably go with a dialogue box asking for box length width & height
with a section for nipples ~ number of, diameters and lengths
same for fans
now you need to know where to place the nipples etc, so at some point you need to change the UCS, so you probably want the "insertion" point for the nipples relative to some origin on the box
same for the fans
and any other gizmos to be attached

SO, I would
1 create the box,
prompt the user for a "face" for the nipples to be inserted on
change the UCS to that "face"
insert the nipples
repeat the process for the fans etc
and any other gizmos

or take it a step further, have ALL the info in a database and just query the database to create the whole shebang. But you would need to have the info stored in the database in a format that is suitable for the programme.

MGEE

  • Guest
Lisp results based on external data
« Reply #29 on: November 18, 2003, 12:54:17 PM »
O.K. I'm looking at the tutorials for VBAIDE right now. So with the Grace of god I'll develope this application that looks at the XLS sheet to get all the info from, with the exception of the insertion point. Thank you for all your knowledge & TIME.
I'm sure we will be talking more in the future.
Have a GREAT Holiday and God Bless.
MGEE

hendie

  • Guest
Lisp results based on external data
« Reply #30 on: November 20, 2003, 07:26:39 AM »
ok, here's something to get you started....

create userform with 5 textboxes and 1 command button as shown above, double-click the command button and add this code....
Code: [Select]

Private Sub CommandButton1_Click()
 Dim length As Double, width As Double, height As Double
 Dim boxObj As Acad3DSolid
 Dim center As Variant
 Dim BoxPnt As Variant
 Dim cylinderObj As Acad3DSolid
 Dim radius As Double
 Dim Cylcen As Variant
 Dim Cylheight As Double
' get data for the box, first get the insertion point from user
 Me.Hide
    BoxPnt = ThisDrawing.Utility.GetPoint(, "Enter a point for centre of box: ")
    length = TextBox1.Value
    width = TextBox2.Value
    height = TextBox3.Value
' now create the box
 Set boxObj = ThisDrawing.ModelSpace.AddBox(BoxPnt, length, width, height)
' before we can add the cylinder, we need to define a new UCS and set it current
' So, let's get the current UCS so we can restore it later
 Dim UCSColl As AcadUCSs
    Set UCSColl = ThisDrawing.UserCoordinateSystems
 Dim ucsObj As AcadUCS
 Dim CurrUCS As AcadUCS
    Set CurrUCS = ThisDrawing.ActiveUCS
' Now change the viewing direction so it's easier to place the cylinder
 Dim NewDirection(0 To 2) As Double
        NewDirection(0) = -1: NewDirection(1) = -1: NewDirection(2) = 1
        ThisDrawing.ActiveViewport.Direction = NewDirection
        ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport
    ZoomAll ' so we can see the box we just created
' Now we can create the new UCS by picking 3 points on a box face
    Dim origin As Variant
    Dim xAxisPnt As Variant
    Dim yAxisPnt As Variant
        origin = ThisDrawing.Utility.GetPoint(, "Enter ORIGIN point for face: ")
        xAxisPnt = ThisDrawing.Utility.GetPoint(, "Enter point on X Axis : ")
        yAxisPnt = ThisDrawing.Utility.GetPoint(, "Enter point on Y Axis : ")
    Set ucsObj = UCSColl.Add(origin, xAxisPnt, yAxisPnt, "Face1")
    ThisDrawing.ActiveUCS = ucsObj
' now get the cylinder values from the form
    radius = TextBox4.Value
    Cylheight = TextBox5.Value
 ' now get the insertion point of the cylinder
    Cylcen = ThisDrawing.Utility.GetPoint(, "Enter a point for centre of cylinder: ")
 ' and since we've got the point in the World UCS we need to convert it to our new UCS
  Cylcen = ThisDrawing.Utility.TranslateCoordinates(Cylcen, acWorld, acUCS, False)
    Dim Cyl(0 To 2) As Double
        Cyl(0) = Cylcen(0)
        Cyl(1) = Cylcen(1)
' but since the solid is created using the picked point as the object CENTRE, we
' need to change the "Z" value so that the object is created on the face of the box
        Cyl(2) = 0 + (Cylheight / 2)
' and create the cylinder
 Set cylinderObj = ThisDrawing.ModelSpace.AddCylinder(Cyl, radius, Cylheight)
' then transform it to our new UCS
 Dim TransMatrix As Variant
    TransMatrix = ucsObj.GetUCSMatrix()
    cylinderObj.TransformBy (TransMatrix)
    cylinderObj.Update
   
    ZoomAll

Unload Me
 
End Sub


I've given this as an example. It will prompt you for an insertion point for the "box", then ask for 3 points for a new UCS, then create the cylinder on the new UCS.
At least it should get you started.