Bª™ªN1534592500 Posted April 20, 2020 Share Posted April 20, 2020 (edited) Good day, could you please help me converting this code (late binding) so that it can work to most versions of AutoCAD without referencing a specific acx##enu.tlb? Sub ExportLine() Dim acadApp As Object Dim acadDoc As Object Dim currentSelectionSet As Object Dim ent As Object Dim oLine As Object Dim n As Long Dim intGroupCode(0) As Integer Dim varDataCode(0) As Variant Set acadApp = GetObject(, "AutoCAD.Application") Set acadDoc = acadApp.ActiveDocument intGroupCode(0) = 0 varDataCode(0) = "Line" acadDoc.SelectionSets.Item("Lne").Delete Set currentSelectionSet = acadDoc.SelectionSets.Add("Lne") n = 1 For Each ent In currentSelectionSet If TypeOf ent Is AcadLine Then 'This line is a problem Set oLine = ent Cells(n, 1) = oLine.StartPoint(0) Cells(n, 2) = oLine.StartPoint(1) Cells(n, 3) = oLine.StartPoint(2) Cells(n, 4) = oLine.EndPoint(0) Cells(n, 5) = oLine.EndPoint(1) Cells(n, 6) = oLine.EndPoint(2) End If Next Set acadApp = Nothing Set acadDoc = Nothing MsgBox "Done" Exit Sub Edited April 28, 2020 by Bª™ªN1534592500 Quote Link to comment Share on other sites More sharing options...
PeterPan9720 Posted April 20, 2020 Share Posted April 20, 2020 Hi, Reading your post seems you are developing above procedure inside Excel Vba module it's correct ? Could you try to do the opposite, developing the procedure inside Autodesk VBA module so you will be use the last version of autocad, selecting the object you need to pass info to excel and so on. This is only a first impression, or suggestion. I'll try to run your code and see what's happen. Bye Quote Link to comment Share on other sites More sharing options...
PeterPan9720 Posted April 20, 2020 Share Posted April 20, 2020 (edited) Hi, I tried your code with Autocad Mechanical 2019 and Excel 2016, inside Excel VBA development area, inserting also a user form with optionbutton, making below modification it seems to run. I tried also to change line color and working fine cell color background on excel. I made some modification to variable declaration. In a first time I had some problem retrieving line Start and End points coords, later I made a modification Variable Declaration and it's running fine. I suggest to check if the object inside "ent" variable it's really a line (perhaps could be a polyline). Sheets(1).Activate Dim acadApp As Object Dim acadDoc As AcadDocument Dim currentSelectionSet As Object Dim ent As Object Dim oLine As AcadLine For your info below image with reference library in Execl Project Finally I don't understand what do you want to do with : If UserForm1.OptionButton2.Value = True Then currentSelectionSet.Select acSelectionSetPrevious, , , intGroupCode, varDataCode 'This line is a problem Else currentSelectionSet.Select acSelectionSetAll, , , intGroupCode, varDataCode 'This line is a problem Bye Edited April 20, 2020 by PeterPan9720 1 Quote Link to comment Share on other sites More sharing options...
Bª™ªN1534592500 Posted April 20, 2020 Author Share Posted April 20, 2020 Thanks for your reply PeterPan. I would like to distribute the spreadsheet which should work for all versions of AutoCAD which is why I am avoiding to reference a specific AutoCAD library. I don't like to create multiple copies of spreadsheet and only changes are the reference from different AutoCAD versions. By the way, I am locking the VBA project which is why the user cannot change the reference. The original code was referenced to AutoCAD 2018 and it was working fine. But when I try to use late binding (eg. Changing Dim acadDoc as AcadDocument to Object, etc) and remove the AutoCAD 2018 Type Library, it doesn't work. With regards to the acSelectionSetPrevious, this was from a very old version of AutoCAD. I believe there was a bug in getting the active selection which is why I did this work around. Quote Link to comment Share on other sites More sharing options...
PeterPan9720 Posted April 20, 2020 Share Posted April 20, 2020 4 minutes ago, Bª™ªN1534592500 said: Thanks for your reply PeterPan. I would like to distribute the spreadsheet which should work for all versions of AutoCAD which is why I am avoiding to reference a specific AutoCAD library. I don't like to create multiple copies of spreadsheet and only changes are the reference from different AutoCAD versions. By the way, I am locking the VBA project which is why the user cannot change the reference. The original code was referenced to AutoCAD 2018 and it was working fine. But when I try to use late binding (eg. Changing Dim acadDoc as AcadDocument to Object, etc) and remove the AutoCAD 2018 Type Library, it doesn't work. With regards to the acSelectionSetPrevious, this was from a very old version of AutoCAD. I believe there was a bug in getting the active selection which is why I did this work around. Ok I understand your issue, but at least something shall be fixed if other software are variable and in my opinion this shall be Autocad. As alternative I'm searching a trick to avoid to be tied with Autocad library version, but I'm not sure. I'll keep you updated. 1 Quote Link to comment Share on other sites More sharing options...
PeterPan9720 Posted April 23, 2020 Share Posted April 23, 2020 On 4/20/2020 at 7:26 PM, PeterPan9720 said: Ok I understand your issue, but at least something shall be fixed if other software are variable and in my opinion this shall be Autocad. As alternative I'm searching a trick to avoid to be tied with Autocad library version, but I'm not sure. I'll keep you updated. Hi @Bª™ªN1534592500, here the code for retrieving active project reference, so starting from active reference library you can select type of declaration before starting the selection part of your code For Each Ref In ActiveWorkbook.VBProject.References RefName = Ref.Name Debug.Print "REF NAME "; RefName RefDesc = Ref.Description Debug.Print "DESCRIPTION "; RefDesc RefPath = Ref.FullPath Debug.Print "PATH "; RefPath Next I hope this could solve probably only some of your issue. However I'll investigate more. Quote Link to comment Share on other sites More sharing options...
Bª™ªN1534592500 Posted April 25, 2020 Author Share Posted April 25, 2020 Many thanks PeterPan, I appreciate your effort. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.