+ Reply to Thread
Results 1 to 8 of 8

Plotting coordinates in VBA from a shape imported from AutoCAD

  1. #1
    Registered User
    Join Date
    10-07-2019
    Location
    Auckland, New Zealand
    MS-Off Ver
    o365
    Posts
    4

    Plotting coordinates in VBA from a shape imported from AutoCAD

    Hi,

    I've imported a shape from AutoCAD as a number of x,y coordinates in order to redraw the shape in Excel. However, I'm not sure how to write a macro to actually use the points. My design manager told me not to use a Chart or ChartObject, but instead to script it, but I'm not sure how, and he's unsure too.. Ultimately the shape will be transferred to a CNC plotting machine to cut the actual shape out of carbon fibre.

    Hope I've given enough info, please let me know if more is required.

    Kind regards,

    Pete

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,803

    Re: Plotting coordinates in VBA from a shape imported from AutoCAD

    This is way out of my league. A few internet searches, however, and I see that a common programming language for CNC machines is called Gcode (https://en.wikipedia.org/wiki/G-code ). A few more internet searches (in particluar, a search for "Excel to Gcode CNC") finds a few sites talking about how to use Excel to generate Gcode (one result: https://www.cnczone.com/forums/g-cod.../8337-cnc.html ).

    As near as I can tell, the overall process is to take your CAD dwg or dxf file, pass it through something that can turn the drawing into Gcode. I don't see anything built into Excel/VBA that knows how to do that. I expect that someone who knows how to generate Gcode from a drawing could convince Excel/VBA to generate the Gcode. We are pretty good at Excel. If you can help us with the non-Excel task of understanding how to go from x,y coordinates to Gcode, we might be able to help you program this into Excel.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    10-07-2019
    Location
    Auckland, New Zealand
    MS-Off Ver
    o365
    Posts
    4

    Re: Plotting coordinates in VBA from a shape imported from AutoCAD

    Hi MrShorty, we have the VBA code that will convert the drawing to G-Code, the part I'm struggling with is taking the x,y coordinates from the spreadsheet and using them to draw the shape in Excel.. The VBA code we currently have will draw a table in the spreadsheet (a representation of the CNC table), and compute the lengths, directions, etc to lay the carbon fibre on the CNC table as per the shape required, though it can only determine rectangles, whereas my task at the moment is to create a non-rectangular shape and determine the fibre layout so as not to waste a huge amount of fibre. I'm thinking my question is more about how to draw the shape in Excel using VBA, using the coordinates that I have from AutoCAD - the coordinates are currently in a "112.36, 112.78" format in the spreadsheet, I'm still trying to get up to speed with VBA to work out how to draw from the coordinates.

    Thanks,
    Pete

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,803

    Re: Plotting coordinates in VBA from a shape imported from AutoCAD

    We probably need to know exactly what kind of input the current VBA code needs. Any kind of drawing (like a jpg or bitmap or similar) or does it require a very specific type of drawing?

  5. #5
    Registered User
    Join Date
    10-07-2019
    Location
    Auckland, New Zealand
    MS-Off Ver
    o365
    Posts
    4

    Re: Plotting coordinates in VBA from a shape imported from AutoCAD

    The nearest I could do would be to paste a section of the current code ...
    Please Login or Register  to view this content.
    Not sure if this helps.. I suspect I might need to create another function to import the coordinates, I'm not sure.
    Last edited by davesexcel; 10-07-2019 at 11:16 PM.

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,803

    Re: Plotting coordinates in VBA from a shape imported from AutoCAD

    This forum can be strict about rules, like putting code within code tags. You should edit your post to add these code tags (see the forum rules FAQ if you are unsure how to use code tags) to avoid getting your topic closed.

    It looks like your code here is using a drawing shape object (https://docs.microsoft.com/en-us/off...pi/excel.shape ). It creates a shape, then adds a rectangle (using a function of yours called addRectangle()). XLeft and YBottom, I would expect, hold some kind of X, Y coordinate information that positions the shape (follow the links to the .Top and .Left properties to understand how those are used), then uses two more value to determine the size of the rectangle.

    If your only real question is how to read text strings in from the spreadsheet, you can use the Range() object or Cells() object to locate a cell, then use the .Value, .Value2, or .Text properties to read the text string (https://docs.microsoft.com/en-us/off....range(object) ). You can use VBA's Split() function to separate the comma delimited string into two strings (https://docs.microsoft.com/en-us/off...split-function ). You may also need the CDBl() function to convert the strings to doubles.

    If you want to add shapes other than rectangles, I expect that will require a modification of the addRectangle() function, which you have not shared, or similar separate functions that will add the desired shape (and a decision structure to decide what shape to add.

    AS I said, this is all above my pay grade. Look through those help files to understand how the Shape object works and learn about other drawing objects you can add. Let us know what you are having trouble understanding, and we'll see what we can help with.

    PS: As I noted, it will depend on exactly what your procedure requires when it goes to convert the drawing to Gcode. I wonder if it would be easier to draw the shape in a scatter chart, then convert the scatter chart to a picture. I don't know exactly how to do that, but it might be easier than trying to draw the shape as a drawing object.

  7. #7
    Registered User
    Join Date
    10-07-2019
    Location
    Auckland, New Zealand
    MS-Off Ver
    o365
    Posts
    4

    Re: Plotting coordinates in VBA from a shape imported from AutoCAD

    Great, will have a look through those files.

    Thank you very much for your help, it's greatly appreciated.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,419

    Re: Plotting coordinates in VBA from a shape imported from AutoCAD

    This will draw a freeform shape based on a set of x and y coordinates that describe the corners of the shape.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find coordinates of a line shape
    By Will T. in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2017, 04:20 PM
  2. [SOLVED] Plotting coordinates,connect points
    By john55 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-25-2014, 06:57 AM
  3. Excel and AutoCAD plotting issue
    By cheddarthief in forum Excel General
    Replies: 0
    Last Post: 08-25-2011, 02:52 PM
  4. Excel 2008 : Shape and coordinates?
    By saapas in forum Excel General
    Replies: 1
    Last Post: 10-02-2010, 04:58 AM
  5. Extract AutoCAD XYZ coordinates
    By rkoog in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-29-2009, 08:35 AM
  6. autocad object coordinates
    By apka in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-10-2008, 02:03 PM
  7. [SOLVED] Help Plotting Cartesian Coordinates
    By Gizzard in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 03-29-2005, 01:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1