Reading attributes from dwg and importing into web page

Reading attributes from dwg and importing into web page

Anonymous
Not applicable
218 Views
4 Replies
Message 1 of 5

Reading attributes from dwg and importing into web page

Anonymous
Not applicable
Hi All,

I am a newbie to VB programming and have a question for the group. I am
hoping someone has tackled this problem already and that there might be some
source code out there that I can learn from to develop my project.

We have a SQL database that we have developed to keep track of our drawings,
rev levels, BOM's, where used, etc. The user interface is through Internet
Explorer, it allows all our company personal to access engineering documents
of all types, from anywhere and at anytime.

Some of the info we keep track of is: Rev Date, Material, Size and Hardness.
I would like to write a VB program that that will go out and read the
attributes we have in our dwg file and place them in their corresponding
input boxes on the web page.

What I envision is on our web page there is a button "Get Info", that when
clicked would launch a VB program that would bring up a common dialog box to
go and select the appropriate AutoCAD file. After selecting the file, the
program would go in and read the needed attributes (without launching a
session of AutoCAD) and return them to their appropriate input boxes on the
web page.

I am probably in way over my head on this one, but I have found that is a
good way to learn by tackling a project that will be useful to me.

Below is some of the html from our web page.

Thanks for you input,

Anna Maria Wood
Auer Precision, Inc.
Mesa, Arizona

----------------------------------------------------------------------------
-----------------------


otherdrawing





















Rev Date: maxLength=20 value=""> Material: maxLength=20 value="">
Size: maxLength=20 value=""> Hardness: maxLength=20 value="">



onclick="thisPage._fireEvent('btnGetInfo','onclick'); return false;">


0 Likes
219 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Well, I have been working on this project this weekend and here is what I
have so far. I have not been able to find a good example of extracting
specific attributes from a specific block. Considering I have done zero
programming in my life I am happy that I have some part of this working.
Just could use some help over this little hump.

My code is shown below and I would appreciate some help for getting the
attributes out of a block and into a variable. Then I will work on it some
more to figuire out how to get into a web page. The trouble area is at the
bottom of the code.

Thanks for your input,

Anna Wood
----------------------------------------------------------------------------
----------------------------

VERSION 5.00
Begin VB.Form frmExtractAttributes
Caption = "Update PartMaster Info"
ClientHeight = 2205
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 2205
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtRevision
Height = 495
Left = 2760
TabIndex = 3
Top = 360
Width = 1700
End
Begin VB.TextBox txtPartNumber
Height = 495
Left = 120
TabIndex = 2
Top = 360
Width = 2300
End
Begin VB.CommandButton cmdExit
Caption = "Exit"
Height = 495
Left = 3240
TabIndex = 1
Top = 1440
Width = 1215
End
Begin VB.CommandButton cmdStart
Caption = "Start"
Height = 495
Left = 120
TabIndex = 0
Top = 1440
Width = 1215
End
Begin VB.Label lblRevision
Caption = "Revision"
Height = 255
Left = 2760
TabIndex = 5
Top = 120
Width = 1700
End
Begin VB.Label lblPartNumber
Caption = "Part Number"
Height = 255
Left = 120
TabIndex = 4
Top = 120
Width = 2300
End
End
Attribute VB_Name = "frmExtractAttributes"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Option Explicit
Public appAutoCad As Object
Public docAutoCad As Object
Public mspace As Object
Public appPartMaster As Object
Dim blockObj As AcadBlock
Dim attributeObj As AcadAttribute
Dim PartNumber As String
Dim Revision As String

Private Sub cmdExit_Click()
Unload frmExtractAttributes
End
End Sub

Private Sub cmdStart_Click()

'Load PartMaster
Set appPartMaster = GetObject("", "InternetExplorer.Application")
If Err <> 0 Then
Err.Clear
Set appPartMaster = CreateObject("InternetExplorer.Application")
If Err <> 0 Then
MsgBox "Could Not Load PartMaster.", vbExclamation
End
End If
End If
appPartMaster.Visible = True
appPartMaster.navigate "http://www.acrodesigns.com/"

End Sub

Private Sub Form_Load()
On Error Resume Next
'Load AutoCad
Set appAutoCad = GetObject(, "AutoCAD.Application")
If Err Then
Err.Clear
MsgBox "AutoCAD is not running. Please exit and start AutoCAD.",
vbExclamation
cmdStart.Enabled = False
Else
Set docAutoCad = appAutoCad.ActiveDocument
Set mspace = docAutoCad.ModelSpace
End If

'--------------------------------------------------------------
'Problem area in code, I wish to access a block named 02-TITLE,
'then extract the attribute tag TOOL_NO. and
'place that text string for that tag in a variable called PartNumber.

For Each blockObj In mspace
If blockObj.Name = "02-TITLE" Then
If attributeObj.TagString = "TOOL_NO." Then
PartNumber = attributeObj.TextString
End If
End If
Next blockObj

Let txtPartNumber = PartNumber

'----------------------------------------------------------------

End Sub

----------------------------------------------------------------------------
------------------------------
"Anna Maria Wood" wrote in message
news:ef34252.-1@WebX.SaUCah8kaAW...
> Hi All,
>
> I am a newbie to VB programming and have a question for the group. I am
> hoping someone has tackled this problem already and that there might be
some
> source code out there that I can learn from to develop my project.
>
> We have a SQL database that we have developed to keep track of our
drawings,
> rev levels, BOM's, where used, etc. The user interface is through
Internet
> Explorer, it allows all our company personal to access engineering
documents
> of all types, from anywhere and at anytime.
>
> Some of the info we keep track of is: Rev Date, Material, Size and
Hardness.
> I would like to write a VB program that that will go out and read the
> attributes we have in our dwg file and place them in their corresponding
> input boxes on the web page.
>
> What I envision is on our web page there is a button "Get Info", that when
> clicked would launch a VB program that would bring up a common dialog box
to
> go and select the appropriate AutoCAD file. After selecting the file, the
> program would go in and read the needed attributes (without launching a
> session of AutoCAD) and return them to their appropriate input boxes on
the
> web page.
>
> I am probably in way over my head on this one, but I have found that is a
> good way to learn by tackling a project that will be useful to me.
>
> Below is some of the html from our web page.
>
> Thanks for you input,
>
> Anna Maria Wood
> Auer Precision, Inc.
> Mesa, Arizona
>
> --------------------------------------------------------------------------
--
> -----------------------
>
>
> otherdrawing
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
Rev Date: > maxLength=20 value="">Material: > maxLength=20 value="">
Size: > maxLength=20 value="">Hardness: > maxLength=20 value="">

>
>
> onclick="thisPage._fireEvent('btnGetInfo','onclick'); return false;">
>
>
>
>
0 Likes
Message 3 of 5

Anonymous
Not applicable
Hi Anna Maria.

This code (made in A2K VBA) will show how to get a specfic block, and get
the attributes in it.
To use this in your project, replace "ThisDrawing" with "docAutoCad"

--------------------------------------------------------------------------
Option Explicit

Sub Test()

Dim ssAtt As AcadSelectionSet
Dim oBlock As AcadBlockReference
Dim oAtts As Variant
Dim dxfcode(1) As Integer
Dim dxfdata(1) As Variant
Dim BlockName As String
Dim TagString As String
Dim attCounter As Integer

' Here we set the NAME of the block we're searching for...
BlockName = "BlockName" ' NOT Casesensitive
' Here we set the Attribute TagString from the Block(s) we want.
TagString = "ATTRIBUTES TAGSTRING" ' CASESENSITIVE. Use UPPERCASE HERE!

' Here, we build a filter for our selectionset.
dxfcode(0) = 0
dxfdata(0) = "INSERT"
dxfcode(1) = 2
dxfdata(1) = BlockName

' Here we create the Selectionset
Set ssAtt = ThisDrawing.SelectionSets.Add("Att")

' Here we collect all the blocks that match the filter
ssAtt.Select acSelectionSetAll, , , dxfcode, dxfdata

' If there is at least 1 instance of the block in the drawing...
If ssAtt.Count > 0 Then
' .. iterate through them...
For Each oBlock In ssAtt
' ... get all the attributes in the block..
oAtts = oBlock.GetAttributes
' ... iterate through all the attributes...
For attCounter = LBound(oAtts) To UBound(oAtts)
' If the Attributes Tagstring match out tagstring...
If UCase(oAtts(attCounter).TagString) = TagString Then
' ... then tell us with a MsgBox!
MsgBox oAtts(attCounter).TextString
End If
Next
Next
End If

' Delete the selectionset when we're done with it.
ssAtt.Delete

End Sub

--------------------------------------------------------------------------

Hope this helps you.

Trond Hasse Lie
Norway
0 Likes
Message 4 of 5

Anonymous
Not applicable
Anna Maria,

Maybe you can use the next peace of code. With this you can extract 1 or
more attributes
from your block.

==========
Dim atts As Variant, ss As AcadSelectionSet
Dim fType(0 To 1) As Integer, fData(0 To 1)

fType(0) = 0: fData(0) = "INSERT"
fType(1) = 2: fData(1) = "02-TITLE"
ss.Select acSelectionSetAll, , , fType, fData

If ss.Count > 0 Then
For i = 0 To ss.Count - 1
atts = ss.Item(i).GetAttributes
For j = LBound(atts) To UBound(atts)
Select Case UCase(atts(j).TagString)
Case "TOOL_NO. "
PartNumber = atts(j).TextString

Case "xxx"


etc. etc. etc.

Case Else
End Select
Next
Next
End If
========

Rene

(With thanks to Frank Oquendo)
0 Likes
Message 5 of 5

Anonymous
Not applicable


Hi anna,

just refer the code of mine. Its a part only. I beleive you can follow.
This uses attributes.

I am using ms Access database and VB forms to draw in AutoCAD

find your way. If you need any further help mail me

N.Murugan

Public Function WriteOneBarData(PassY As Double)

  Dim Barloc As Variant

  Dim barv As Variant

  Dim BarIndicate As String

  Dim TotBarNos As String

  Dim dpt(0 To 2) As Double

   Barloc = Array(49, 58, 68, 78, 89, 101, 107, 119, 129,
_

                
139, 149, 159, 169, 179, 189)

   BarIndicate = TypeOfBar & CStr _

                   
(BarRecord.Fields("SizeOfBar"))

   TotBarNos = CStr(BarRecord.Fields("MemberNos") * _

                   
BarRecord.Fields("NoOfBars"))

Dim a, b, c, d, e, f, g, h, i, j, k, l, m, n, o As Variant

 

a = BarRecord.Fields("BarMark")

b = BarIndicate

c = BarRecord.Fields("MemberNos")

d = BarRecord.Fields("NoOfBars")

e = TotBarNos

f = BarRecord.Fields("DimTotal")

g = BarRecord.Fields("ShapeCode")

h = BarRecord.Fields("DimA")

i = BarRecord.Fields("DimB")

j = BarRecord.Fields("DimC")

k = BarRecord.Fields("DimD")

l = BarRecord.Fields("DimE")

m = BarRecord.Fields("DimF")

n = BarRecord.Fields("DimG")

o = BarRecord.Fields("DimH")

 

 barv = Array(a, b, c, d, e, f, g, h, i, j, k, l, k, m, n, o)

   Set blockref = AcadCallObject.ActiveDocument.ModelSpace.
_

   InsertBlock(iPnt, "BarData", 1, 1, 0)

   If blockref.HasAttributes Then

    ArrayAttributes = blockref.GetAttributes

     For ii = LBound(ArrayAttributes) To UBound(ArrayAttributes)

      Set attref = ArrayAttributes(ii)

      If IsNull(barv(ii)) Then

      attref.TextString = " "

      Else

      attref.TextString = barv(ii)

      End If

      attref.HorizontalAlignment = acHorizontalAlignmentRight

      dpt(0) = Barloc(ii)

      dpt(1) = PassY - 4#

      dpt(2) = 0#

      attref.TextAlignmentPoint = dpt

      attref.Update

     Next

    blockref.Update

End If

WrBool = True

End Function

 

Anna Maria Wood wrote:

Hi All, I am a newbie to VB programming and have
a question for the group. I am hoping someone has tackled this problem
already and that there might be some source code out there that I can learn
from to develop my project. We have a SQL database that we have developed
to keep track of our drawings, rev levels, BOM's, where used, etc. The
user interface is through Internet Explorer, it allows all our company
personal to access engineering documents of all types, from anywhere and
at anytime. Some of the info we keep track of is: Rev Date, Material, Size
and Hardness. I would like to write a VB program that that will go out
and read the attributes we have in our dwg file and place them in their
corresponding input boxes on the web page. What I envision is on our web
page there is a button "Get Info", that when clicked would launch a VB
program that would bring up a common dialog box to go and select the appropriate
AutoCAD file. After selecting the file, the program would go in and read
the needed attributes (without launching a session of AutoCAD) and return
them to their appropriate input boxes on the web page. I am probably in
way over my head on this one, but I have found that is a good way to learn
by tackling a project that will be useful to me. Below is some of the html
from our web page. Thanks for you input, Anna Maria Wood Auer Precision,
Inc. Mesa, Arizona ----------------------------------------------------------------------------
----------------------- 





















Rev Date:  maxLength=20 value=""> Material:  maxLength=20 value="">
Size:  maxLength=20 value=""> Hardness:  maxLength=20 value="">


onclick="thisPage._fireEvent('btnGetInfo','onclick'); return false;">

0 Likes