Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Member
 
Posts: 46
Default Modify this Array

Is it possible to modify the array so that it checks the header to ensure that value is put in the correct column?

The following array will get the block attribute values out of a ACAD drawing and export them to excel. However not all attributes have the same headers and values. Some blocks fill in more columns with data than the others. I have also noticed at times the order of the headers change so that seems to complicate things a little. I have attached a sample showing how for instance the "tag" values do not line up...

Please, any help is appreciated



Code:

Public Function ExtractAtts()

        'Open Excel file
        Dim Xl As Excel.Application
        Dim XlSheet As Object
        Dim XlWorkbook As Object
        
        Dim RowNum As Integer
        Dim Header As Boolean
        Dim elem As AcadEntity
        Dim Array1 As Variant
        Dim count As Integer
        
        FilePath = ("C:\Desktop\TempImport.xlsx")

        'Launch Excel and Get Attributes***************************
        Set Xl = New Excel.Application
        Set XlBook = Xl.Workbooks.Open(FilePath, ReadOnly:=False)
        
        Set XlSheet = XlBook.Worksheets("DwgAttributes")
        Xl.Visible = True 'False
       
       
        RowNum = 1
        Header = False
                
        'Extract Attyributes and populate the excel Tab
        With Xl.Worksheets("DwgAttributes")
            
             On Error Resume Next
            .Cells.Clear
        
        ' Iterate through model space finding
        ' all block references.
        For Each elem In ThisDrawing.ModelSpace
            With elem
            ' When a block reference has been found,
            ' check it for attributes
            If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
              If .HasAttributes Then
                ' Get the attributes
                Array1 = .GetAttributes
 
'MODIFY THIS ARRAY*****
           
                ' Copy the Tagstrings for the Attributes into Excel
                For count = LBound(Array1) To UBound(Array1)
                  If Header = False Then
                    If StrComp(Array1(count).EntityName, "AcDbAttribute", 1) = 0 Then
                      XlSheet.Range("A1") = "HANDLE" 'get the block handle 
                      XlSheet.Cells(RowNum, count + 2).Value = Array1(count).TagString
                    End If
                  End If
            
                Next count
        
            RowNum = RowNum + 1
            For count = LBound(Array1) To UBound(Array1)
              If XlSheet.Range("A" & RowNum) = False Then
                 XlSheet.Range("A" & RowNum) = "'" & "'" & elem.Handle 'Block Handle Header
               End If
              XlSheet.Cells(RowNum, count + 2).Value = Array1(count).TextString
             
            Next count
        
            Header = True
          End If
         End If
        End With
       Next elem
        
 Xl.Sheets("Sheet1").Cells.EntireColumn.AutoFit
        
 End With
        
        Xl.DisplayAlerts = False
        XlWorkbook.Save
        XlWorkbook.Close True '*** uncomment to keep open
        Xl.DisplayAlerts = True
        Xl.Quit
        
        Set XlSheet = Nothing
        Set XlWorkbook = Nothing
        Set Xl = Nothing
        GoTo Exit_Sub
       
        
Exit_XL_App:
        
        MsgBox Err.Number & " - " & Err.Description & " Error occurred in Excel App Process"
        
        Xl.DisplayAlerts = False
        XlWorkbook.Close True '*** uncomment to keep open
        Xl.DisplayAlerts = True
        Xl.Quit
        
        Set XlSheet = Nothing
        Set XlWorkbook = Nothing
        Set Xl = Nothing
        GoTo Exit_Sub
        
        
Exit_Sub:


End Function
Attached Files
File Type: zip Book1.zip (6.6 KB, 58 views)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Modify this Array

Firstly, this 'very messy and inefficient' code sample needs a serious
revision to get rid of all the unnecessary duplication and If...Then
constructs.

One problem I see right away after reading your sample file is that
you're processing 'components' of an assembly, and so not all will have
the same 'attributes' by nature of their individual design. In this
case you need a 'map' enum for your headers so you can assign non-blank
attributes to their respective 'fields' so the data ends up in the
correct columns. This requires a methodology that enums attributes so
you can assign column indexes to values. It also requires your 'same'
attributes be named identically so they can be identified for their
respective position in the data table.

I switched from using ACAD to using SolidWorks back in the 90's and so
its equivalent to model 'attributes' is model 'properties'. I use model
templates that have the same list of properties (via PropertyManager)
for all (sldprt, sldasm) so list number of 'fields' is the same for all
components and assemblies. (Assemblies can contain sub-assemblies) I
don't have to figure things out 'after-the-fact' and so I can't help
you here much beyond approach concept...

1. Loop all components in the model to build a unique list of
'attribute' IDs. (This can be as simple in construct as a delimited
string list!)

2. Loop again to find the index of each component's 'attribute' in the
string list. (This can be as simple as using a counter in a For...Each
constructs!)

3. Assign the value of the components 'attribute' to the counter
position in your 'output array'. The output array should be 2D...

ReDim vaDataOut(<component.count, <attributes.count)

...so all data is processed in memory. Make sure you have a proper
handle on the 'count' values as to their 'base' being zero or 1 so
vaDataOut is correctly dimmed! Note that this array is being dimmed
dynamically and so must be done using the 'ReDim' statement in order to
use variables for the respective 'count' values.

4. Once all data is assign, 'dump' vaDataOut into the worksheet.

However, I strongly suggest implementing a standard set of 'attributes'
for all part/assembly files so you have a consistent 'set' of value
'placeholders' regardless if all are used for every part/assembly file.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Member
 
Posts: 46
Default

Thanks for the reply...

I was looking at some examples of the ReDim vaDataOut and wow that is way over my head, but I will do some research... I'm not skilled at vba and not sure I can figure that out. I just know enough to put a few pieces code together and hope it works...

Just for clarification, the headers shown in the example accounts for all the attribute values in the blocks used...
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Modify this Array

Thanks for the reply...

I was looking at some examples of the ReDim vaDataOut and wow that is
way over my head, but I will do some research... I'm not skilled at
vba and not sure I can figure that out. I just know enough to put a
few pieces code together and hope it works...

Just for clarification, the headers shown in the example accounts for
all the attribute values in the blocks used...


+-------------------------------------------------------------------+
+-------------------------------------------------------------------+


According to what I've researched.., Enhanced Attribute Manager would
be your equivalent for the PropertyLinks manager I use in SolidWorks.
If you give all models a standard 'set' of attributes you should be
alright. As for the code...

Do me a favor and 'dump' Array1 into a blank worksheet...

With Xl.Sheets("Sheet2").Range("A1")
.Resize(UBound(Array1), UBound(Array1, 2) = Array1
End With

...so I can see an example of a set of attributes, and post a link to
the file.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Modify this Array

Insert the code to dump Array1 after this line...

Array1 = .GetAttributes

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Modify this Array

Can you explain why you open a specific workbook and clear the target
sheet? Could you not just use a new workbook?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #7   Report Post  
Member
 
Posts: 46
Default

Quote:
Originally Posted by GS[_2_] View Post
Can you explain why you open a specific workbook and clear the target
sheet? Could you not just use a new workbook?
I am using a specific workbook because I have other tabs in the WB that has information from a field panel. I am updating the attributes in the dwg with the actual information from the field panel description.

Example: the field technician will put a description and extended labels of a device that the engineer would have to update as part of the as-builts.
The intent is to automate that process by updating the dwgAttribute tab and then updating the drawing
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Modify this Array

In the case Array1 is 1D...

With Xl.Sheets("Sheet2").Range("A1")
.Resize(1,UBound(Array1)) = Array1
End With

...and only for 1 elem! That means you have to step through the code and
end it after the data is dumped.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #9   Report Post  
Member
 
Posts: 46
Default

Quote:
Do me a favor and 'dump' Array1 into a blank worksheet...

With Xl.Sheets("Sheet2").Range("A1")
.Resize(UBound(Array1), UBound(Array1, 2) = Array1
End With

...so I can see an example of a set of attributes, and post a link to
the file.
Quote:
Insert the code to dump Array1 after this line...

Array1 = .GetAttributes
Why I tried this Sheet2 is blank. Not sure what I'm doing wrong
Perhaps I could explain it.. I have basically two sets of attributes
----------------------------------------------------------------
Set1
HANDLE, BLOCKNAME, TAG, LABEL1, LABEL2, QTY, MODEL_NUM, DESCRIPTION, VENDOR, CSFM_NUM

Set2 (Has more)
HANDLE, BLOCKNAME, TAG, LOOP, ADDRESS, LABEL1, LABEL2, DEVICE_LABEL, EXTENDED_LABEL, QTY, MODEL_NUM, DESCRIPTION, VENDOR, CSFM_NUM
----------------------------------------------------------------

Currently I am writing them to one sheet and looking for the code to populate the correct cell...
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Modify this Array


Do me a favor and 'dump' Array1 into a blank worksheet...

With Xl.Sheets("Sheet2").Range("A1")
.Resize(UBound(Array1), UBound(Array1, 2) = Array1
End With

...so I can see an example of a set of attributes, and post a link
to the file.


Insert the code to dump Array1 after this line...

Array1 = .GetAttributes


Why I tried this Sheet2 is blank. Not sure what I'm doing wrong
Perhaps I could explain it.. I have basically two sets of attributes
----------------------------------------------------------------
Set1
HANDLE, BLOCKNAME, TAG, LABEL1, LABEL2, QTY, MODEL_NUM, DESCRIPTION,
VENDOR, CSFM_NUM

Set2 (Has more)
HANDLE, BLOCKNAME, TAG, LOOP, ADDRESS, LABEL1, LABEL2, DEVICE_LABEL,
EXTENDED_LABEL, QTY, MODEL_NUM, DESCRIPTION, VENDOR, CSFM_NUM
----------------------------------------------------------------

Currently I am writing them to one sheet and looking for the code to
populate the correct cell...


+-------------------------------------------------------------------+
+-------------------------------------------------------------------+


Okay, this is pretty much what shows as headers in your sample
worksheet. I was wanting to see how .GetAttributes returns values. I'll
go online to see what I can find. What property is these attributes?
(I'm guessing .TagString?) I want to provide code that builds headers
of unique attributes so the values can be assigned to the appropriate
column according to their attribute. I'm also guessing the attribute
value is .TextString?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




  #11   Report Post  
Banned
 
Posts: 11
Default

Chat box - Create and design free live chat box php embed iframe html source code for your website forum blog wap without advertisement.
  #12   Report Post  
Banned
 
Posts: 11
Default

Sim Đoàn Viên Giá Rẻ
Cơ hội cho bạn tiết kiệm tiền điện thoại một cách hợp lư. Là làm sim sinh viên và sim đoàn viên!
liên hệ 0903.636.838 or 0906.904.888
DC: p3010CT10A chung cư Đại Thanh
Nhận chuyển sim thường sang sim SINH VIÊN, đoàn viên KHÔNG CẦN THẺ SINH VIÊN 3 mạng chính Uy tín và Đảm bảo. Chuyên đại lư và khách hàng thn quen. Cam kết có giá tốt nhất nếu làm số lượng.
✔ Viettel x 200 k
...Xem thêm


[center]https://scontent-dfw.xx.fbcdn.net/hp...e1&oe=55A23F97[url=https://www.facebook.com/simsinhviengiare.vn][b]Sim Sinh Viên Mobi Giá Rẻ
  #13   Report Post  
Banned
 
Posts: 11
Default

tin tức nước Nga Tất cả thông tin, h́nh ảnh, video clip về Nga tổng hợp từ tất cả các báo điện tử tại ... Cực để tạo điều kiện thuận lợi cho các công ty của nước này khai thác
đọc báo nga
Xem thêm: http://vietbao.ru/vo-su-aikido-nhat-...post43065.html
  #14   Report Post  
Banned
 
Posts: 11
Default

Sim Sinh Viên Viettel Giá Rẻ
Cơ hội cho bạn tiết kiệm tiền điện thoại một cách hợp lư. Là làm sim sinh viên và sim đoàn viên!
liên hệ 0903.636.838 or 0906.904.888
DC: p3010CT10A chung cư Đại Thanh
Nhận chuyển sim thường sang sim SINH VIÊN, đoàn viên KHÔNG CẦN THẺ SINH VIÊN 3 mạng chính Uy tín và Đảm bảo. Chuyên đại lư và khách hàng thn quen. Cam kết có giá tốt nhất nếu làm số lượng.
✔ Viettel x 200 k
...Xem thêm


[center]https://scontent-dfw.xx.fbcdn.net/hp...e1&oe=55A23F97[url=https://www.facebook.com/simsinhviengiare.vn][b]Sim Đoàn Viên Giá Rẻ
  #15   Report Post  
Junior Member
 
Posts: 6
Default

Mă giảm giá Lazada [/color]Mă giảm giá Lazada, tổng hợp voucher Zalora khuyến măi, coupon Tiki, Cdiscount và các trang web lớn khác, chia sẻ kinh nghiệm mua hàng online.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modify code for multiple sheets-Help defining array ToddEZ Excel Programming 6 October 19th 07 08:52 PM
Modify array function length Fabian Grodek Excel Worksheet Functions 3 August 8th 06 04:45 PM
modify without unprotecting the sheet, array with wrong format filo666 Excel Programming 1 November 22nd 05 10:06 PM
Modify SumIF... Array Formula carl Excel Worksheet Functions 2 May 17th 05 07:52 PM
Modify SumIF... Array Formula Peo Sjoblom Excel Worksheet Functions 0 May 17th 05 06:15 PM


All times are GMT +1. The time now is 11:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"