Consulting

Results 1 to 6 of 6

Thread: Need Help with Excel Macro

  1. #1
    VBAX Newbie
    Joined
    Mar 2024
    Posts
    3
    Location

    Need Help with Excel Macro

    I am creating a macro to import attributes from Autocad entities. The one in partiicular is a feature line.
    I managed to get everything working, but I am trying to get the minimum elevation from the feature line but I don't know what is the correct command for it.
    The section where I have this issue follows below (note that the length and the maximum elevation are working fine, just the minimum elevation that does not work)

    Thisdrawing.Utility.GetEntity returnObj, basePnt, "Select Feature Line: "
    Err.Clear
    returnObj.Update
    ValorLength = Round(returnObj.Length2D, 4)
    MaxElev = Round(returnObj.MaxElevation, 4)
    MinElev = Round(returnObj.MinElevation, 4)
    Can someone help me?

    ps: I use autocad 2021 version

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Welcome to VBAX Bylloo. Its been a while since we've had an Autocad request. Hopefully someone comes along shortly.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    chatGPT has some answer:
    Sub FindMinimumElevation()
        Dim acadApp As Object 'AutoCAD Application
        Dim acadDoc As Object 'AutoCAD Document
        Dim selectionSet As Object 'Selection Set
        Dim entity As Object 'Selected Entity
        Dim minElevation As Double
        Dim elevation As Double
        
        ' Create a new instance of AutoCAD
        Set acadApp = CreateObject("AutoCAD.Application")
        acadApp.Visible = True ' Optionally make AutoCAD visible
        
        ' Get the active document in AutoCAD
        Set acadDoc = acadApp.ActiveDocument
        
        ' Create a selection set to hold the entities
        Set selectionSet = acadDoc.SelectionSets.Add("MySelectionSet")
        
        ' Prompt the user to select the entities
        selectionSet.SelectOnScreen
        
        ' Initialize the minimum elevation to a large value
        minElevation = 999999
        
        ' Loop through each selected entity
        For Each entity In selectionSet
            ' Check if the entity has elevation property (for example, polylines have)
            If entity.HasElevation Then
                ' Get the elevation of the entity
                elevation = entity.Elevation
                
                ' Update the minimum elevation if necessary
                If elevation < minElevation Then
                    minElevation = elevation
                End If
            End If
        Next entity
        
        ' Display the minimum elevation found
        MsgBox "Minimum Elevation: " & minElevation
        
        ' Delete the selection set
        acadDoc.SelectionSets.Item("MySelectionSet").Delete
    End Sub

  4. #4
    VBAX Newbie
    Joined
    Mar 2024
    Posts
    3
    Location
    Tried but it did not work

  5. #5
    can you upload your .acad drawing?

  6. #6
    VBAX Newbie
    Joined
    Mar 2024
    Posts
    3
    Location
    It points an error when I try to upload the CAD file, sorry. But what I am creating is a template spreadsheet, the macro isn't specific to a file. So, when I am testing, I just open a blank CAD file and create the feature line randomly and see if the macro works

    Quote Originally Posted by arnelgp View Post
    can you upload your .acad drawing?

Tags for this Thread

Posting Permissions

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