+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Full Member
    Computer Details
    mien's Computer Details
    Operating System:
    Windows XP
    RAM:
    3GB
    Graphics:
    Compaq Presario V3700
    Using
    AutoCAD 2006
    Join Date
    Feb 2009
    Posts
    42

    AutoCAD plot x,y and z coordinate using AutoCAD VB

    how to plot x,y,z coordinates using autocad VB...can someone give me the script plss

    email me at red_wing86@yahoo.com or add me as ur friend using yahoo massenger

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,737

    Default

    It would be better if the answer was posted on the forums, as other users could benefit from the code provided
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,737

    Default

    When you say
    plot x,y,z coordinates
    what do you mean exactly?

    print coordinates of certain objects to external files? i.e. coords of points to text or excel files...

    Could you please explain further

    Thanks

    Lee
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  4. #4
    Luminous Being dbroada's Avatar
    Computer Details
    dbroada's Computer Details
    Operating System:
    Windows 7 Professional
    Computer:
    Dell
    CPU:
    Intel Xeon E5-1603@2,80GHz
    RAM:
    4GB
    Graphics:
    NVIDA Quadro K600
    Monitor:
    DELL 23" & SAMSUNG 21"
    Discipline
    Electro/Mech
    dbroada's Discipline Details
    Occupation
    Design Engineer
    Discipline
    Electro/Mech
    Using
    Electrical 2013
    Join Date
    Nov 2005
    Location
    Sussex, UK
    Posts
    5,503

    Default

    I assumed the OP wanted a plot window.

    I didn't reply as I didn't have an answer but I did manage to stop myself posting saying answers should be posted in forum. Now you've done that I can agree.
    "That's it. It's one thing for a ghost to terrorize my children, but quite another for him to play my Theremin." Homer Simpson
    "Everything in drafting is logical. Except what isn’t." - Gavin Guile. (from the Lightbringer series of books by Brent Weeks)

    Dave

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,737

    Default

    A plot window...

    maybe something using EXTMIN and EXTMAX?
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  6. #6
    Full Member
    Computer Details
    mien's Computer Details
    Operating System:
    Windows XP
    RAM:
    3GB
    Graphics:
    Compaq Presario V3700
    Using
    AutoCAD 2006
    Join Date
    Feb 2009
    Posts
    42

    Default

    Quote Originally Posted by Lee Mac View Post
    When you say what do you mean exactly?

    print coordinates of certain objects to external files? i.e. coords of points to text or excel files...

    Could you please explain further

    Thanks

    Lee
    coordinate from excel or txt file..plot to autocad using visual basic..
    can someone teach me...thanks

  7. #7
    Forum Newbie
    Using
    AutoCAD 2005
    Join Date
    Feb 2009
    Posts
    3

    Default

    This is my first post and it may or may not be what you're after. I suggest you read and try to understand the code as my error handling here is not the best. I have a user form for picking the file and blocks (which are passed to the routines below) but I can't see how to attach anything here.

    The following code will place blocks at coordinates read from a csv text file (x,y,z,name or x,y,name - your could change the column order easily if you wanted, I just haven't got around to it). The 'name' will be placed if the specified block has an attribute.

    The block you want to use must exist within the dwg.

    The file format is a csv file of either 4 columns (x,y,z,name) or 3 columns(x,y,name).

    Make sure no coordinates are missing.

    For 'x,y,name' a z value of 0 is assumed.


    Code:
     
    Public mstrBlockName As String
    Public blnBlockLabelFailure As Boolean
    Public mstrImportType As String
     
    Public Sub ReadXYFile(strFileName As String)
    'mstrBlockName was set on userform before calling this sub routine
    Dim myFile As Integer
    Dim lngIndex As Long
    Dim strTextLine As String
    Dim arrText As Variant
    Dim intCol As Integer
     
    Dim intSubStrings As Integer
     
    Dim dblX As Double
    Dim dblY As Double
    Dim dblZ As Double
    Dim strName As String
    'strFileName = "C:\GIS\COORD_TEST3.csv" 'change this to your file
    On Error GoTo ErrorHandlerPoint
    ' TODO: Take this check out, have already checked on form.
    If Dir(strFileName) = "" Then
    Call MsgBox(strFileName & " not found", vbExclamation, "Import XYZ Coordinates")
    GoTo TidyUpAndExit
     
    End If
     
    myFile = FreeFile
    Open strFileName For Input As #myFile
     
    Do While Not EOF(myFile)
    Line Input #myFile, strTextLine
    arrText = Split(strTextLine, ",")
     
    If lngIndex = 0 Then ' read first line to determine number columns in file
    intSubStrings = UBound(arrText)
    'Debug.Print intSubStrings
    If intSubStrings = 2 Then 'i.e. 3 columns, we are expecting X,Y,Name
    mstrImportType = "XYName"
    ElseIf intSubStrings = 3 Then 'i.e. 4 columns, we are expecting X,Y,Z and Name
    mstrImportType = "XYZName"
    Else
    mstrImportType = ""
    Call MsgBox("The chosen file was invalid." & _
    vbCrLf & "" & _
    vbCrLf & "File must comprise 3 (X,Y,Name) or 4 (X,Y,Z,Name) columns of data only.", vbExclamation, "Import XYZ Coordinates")
    GoTo TidyUpAndExit
    End If
     
    End If
     
    'if the columns are in the wrong order a type mismatch error will be thrown by the error handler
     
    Select Case mstrImportType
    Case "XYName"
    dblX = arrText(0)
    dblY = arrText(1)
    dblZ = 0
    strName = arrText(2)
     
    Call InsertBlock(dblX, dblY, dblZ, strName)
     
    Case "XYZName"
    dblX = arrText(0)
    dblY = arrText(1)
    dblZ = arrText(2)
    strName = arrText(3)
     
    Call InsertBlock(dblX, dblY, dblZ, strName)
     
    Case Else
    '????????????
     
    End Select
     
    lngIndex = lngIndex + 1
     
    Loop
     
    TidyUpAndExit:
    '**** tidy up e.g. close and set objects to nothing
    Close myFile
    Exit Sub
    ErrorHandlerPoint:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ReadXYFile"
    'could try to catch specific error, e.g possible type mismatch and provide meaningful message
    GoTo TidyUpAndExit
    End Sub
     
    Sub InsertBlock(xx As Double, yy As Double, zz As Double, bAttr As String)
    Dim insertionPnt(0 To 2) As Double
    Dim blockRefObj As AcadBlockReference
    Dim varAttribs As Variant
    Dim intAttribCount As Integer
    'Coordinate 'x=0,y=1,z=2
    insertionPnt(0) = xx#: insertionPnt(1) = yy#: insertionPnt(2) = 0
    'InsertBlock inserts a drawing file or a named block that has been defined in the current drawing.
    Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, mstrBlockName, 1#, 1#, 1#, 0)
    ' Get attribute value(s) from the block.
    varAttribs = blockRefObj.GetAttributes
    'Check how many attributes the block - if 0 set a boolean flag
    intAttribCount = UBound(varAttribs)
    If intAttribCount = -1 Then ' The block has no attributes
    blnBlockLabelFailure = True
    'Call MsgBox("The chosen block has no attributes to label.", vbInformation, "Import XYZ Coordinates")
    Else
    ' We will use only the First attribute in the block found at location Zero.
    ' varAttribs(0) is the first block attribute value.
    ' Note, most programs uses Zero-based counting & therefore the first number is Zero when counting rather than one.
    varAttribs(0).TextString = bAttr
     
    ' Update the block so we can see the new Values applied to the block attribute values above.
    ' This is similar to a localized regen, only the block is updated/regenerated.
    varAttribs(0).Update
    End If
    TidyUpAndExit:
    '**** tidy up e.g. close and set objects to nothing
    Exit Sub
    ErrorHandlerPoint:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure InsertBlock"
    'could try to catch specific error, e.g possible type mismatch and provide meaningful message
    GoTo TidyUpAndExit
    End Sub
    Last edited by fuccaro; 25th Feb 2009 at 09:14 am. Reason: added CODE tags

  8. #8
    Full Member
    Computer Details
    mien's Computer Details
    Operating System:
    Windows XP
    RAM:
    3GB
    Graphics:
    Compaq Presario V3700
    Using
    AutoCAD 2006
    Join Date
    Feb 2009
    Posts
    42

    Default

    thankssssss dvhardy...i will try it..

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,737

    Default

    dvhardy, would you be able to post your code in future within [code] [/ code] tags as it makes it easier to read, follow and copy

    Thanks

    Lee
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  10. #10
    Full Member
    Computer Details
    mien's Computer Details
    Operating System:
    Windows XP
    RAM:
    3GB
    Graphics:
    Compaq Presario V3700
    Using
    AutoCAD 2006
    Join Date
    Feb 2009
    Posts
    42

    Default

    Registered forum members do not see this ad.

    can someone teach me how to class the layer according to height range using visual basic or lips..thanks..

Similar Threads

  1. Replies: 3
    Last Post: 16th Feb 2009, 03:17 am
  2. How to retrive 3D coordinate information of any object from AutoCAD VBA
    By Kshirsagar in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 11th Nov 2008, 11:59 am
  3. Replies: 3
    Last Post: 9th Jun 2008, 09:40 am
  4. Coordinate Systems and AutoCAD
    By JayT in forum AutoCAD Beginners' Area
    Replies: 4
    Last Post: 29th Feb 2008, 06:25 pm
  5. Coordinate from excel to autocad
    By rick_belial in forum AutoCAD Drawing Management & Output
    Replies: 7
    Last Post: 15th Nov 2007, 03:19 pm

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