PDA

View Full Version : Solved: Text file to drawing



nsdhakar
04-05-2005, 02:19 AM
have structured my text file (file.txt) according to ANSYS command file, now i want that when i put this file again in autocadd than it results in a drawing of the same structure frm which the text file is generated.

i am posting myt text file also...


/title , frame

/PREP7

!Enter the height and width of the frame:

300, 400

! Define Keypoints

K, 1,4578.2531,7919.0487

K, 2,11346.8678,11826.9102

K, 3,11346.8678,3072.2707

K, 4,4578.2531,3072.2707

K, 5,11346.8678,7919.0487

K, 6,4578.2531,11826.9102

! Define Lines Linking Keypoints

L,1,2 ! L,keypoint1,keypoint2
L,2,3
L,3,4
L,4,1
L,4,6
L,4,5
L,3,5
L,3,6

! element definition

!

ET,1,LINK1 ! element type #1; spring element
R,1,3250 ! real constant #1; Xsect area: 3200 mm^2
MP,EX,1,200e3 ! material property #1; Young's modulus: 200 GPa


LESIZE,ALL, , ,1,1,1 ! specify divisions on unmeshed lines
LMESH,all ! mesh all lines

!
FINISH ! finish pre-processor
!
/SOLU ! enter solution phase
!
! apply some constraints

DK,1,UX,0,,,UY,UZ ! define a DOF constraint at a keypoint
DK,7,UY,0,,,UZ

!
! apply loads
!

FK,1,FY,-280e3 ! define a force load to a keypoint
FK,3,FY,-210e3
FK,5,FY,-280e3
FK,7,FY,-360e3

!
SOLVE ! solve the resulting system of equations

FINISH ! finish solution

/POST1

PRRSOL,F ! List Reaction Forces
PLDISP,2 ! Plot Deformed shape
PLNSOL,U,SUM,0,1 ! Contour Plot of deflection

ETABLE,SAXL,LS, 1 ! Axial Stress
PRETAB,SAXL ! List Element Table
PLETAB,SAXL,NOAV ! Plot Axial Stress


to make more clear, i have generated my text file by using VBA programming in autocad, i know that to get drawing from this text file also need programming in VBA but i am not getting any idea how to do it.

the problem, to export text file to ansys is solved so the problem remains is the above one.

please help me out http://www.autocadeverything.com/phpBB/images/smiles/icon_sad.gif..its really urgent, deadline is very near http://www.autocadeverything.com/phpBB/images/smiles/icon_sad.gif

thanks

nsdhakar

Tommy
04-05-2005, 08:58 AM
Hi nsdhakar,

:hi:

If you could post a zip file with the VBA project in it I could Reverse it and it would also help a lot determining what you would like to draw.

nsdhakar
04-05-2005, 10:11 AM
Thankyou Tommy for coming forward to help me :)

i am attaching my vba program to generate text file from drwaing of frame structure.

i also have two problems in that vba program, to put the some part in a loop. i have put a NOTE there, it will also be very usefull for me if u can suggest some method to make them in loop. nyway those are small problems.

thanks

nsdhakar

Tommy
04-05-2005, 10:29 AM
I am looking into it. Just so you know :)

Zack Barresse
04-05-2005, 10:39 AM
Tommy is an AutoCad/VBA God!! :yes

Tommy
04-05-2005, 11:07 AM
LOL I would settle for Good (one more o) :rofl:

nsdhakar the below is just the loop you asked for. I haven't tested it yet though. Is this a stress analysis using a mesh for display?


While Element <> vbNullString
'Note: make this part in loop so that it can write these values
'untill user put null value as i did above to get elements end nodes
Print #intFile, " !Apply Load "
Element = ThisDrawing.Utility.GetString(False, _
"enter force load to keypoints like(n,FY,-280e3), " & _
"where n is the node no.:")
Print #intFile, "FK," & Element
'Note: make this part in loop so that it can write these values
'untill user put null value as i did above to get elements end nodes
Print #intFile, " SOLVE "
Print #intFile, " !solve the resulting system of equations "
Print #intFile, " FINISH "
Print #intFile, " !finish solution "
Print #intFile, " /POST1"
Print #intFile, " PRRSOL,F "
Print #intFile, " ! List Reaction Forces "
Print #intFile, " PLDISP,2 "
Print #intFile, " ! Plot Deformed shape"
Print #intFile, " PLNSOL,U,SUM,0,1 "
Print #intFile, " ! Contour Plot of deflection "
Print #intFile, " ETABLE,SAXL,LS, 1 "
Print #intFile, " ! Axial Stress "
Print #intFile, " PRETAB,SAXL "
Print #intFile, " ! List Element Table "
Print #intFile, " PLETAB,SAXL,NOAV "
Print #intFile, " ! Plot Axial Stress "
Wend



I changed the check on the saved file also. Dname holds the name of the drawing not if it has been saved, the message was also fixed (not enough ") .


If Dname = "" Then
MsgBox "The drawing wasn't saved! & Chr$(13) please do save first!"
Exit Sub
End If

If CheckIfNotSaved Then Exit Sub

'the below Function checks if the active drawing has
'been saved or not. Reuse as required

Function CheckIfNotSaved() As Boolean
CheckIfNotSaved = False
If Not ActiveDocument.Saved Then
MsgBox "The drawing wasn't saved!" & Chr$(13) & "Please do save first!"
CheckIfNotSaved = True
End If
End Function

nsdhakar
04-05-2005, 11:08 AM
Thankyou Tommy, :)
i have made change what u posted to make change.

but i want following two parts of the code in loop seperately ...

ThisDrawing.Utility.Prompt "Apply some constraints" & Chr$(14)
Element = _
ThisDrawing.Utility.GetString(False, _
"enter the constraints on the nodes like(n,UX,0,,,UY,UZ ), " & _
"where n is the node no.:")

Print #intFile, "DK," & Element
'Note: make this part in loop so that it can write these values
'untill user put null value as i did above to get elements end nodes


and

Element = ThisDrawing.Utility.GetString(False, _
"enter force load to keypoints like(n,FY,-280e3), " & _
"where n is the node no.:")

Print #intFile, "FK," & Element
'Note: make this part in loop so that it can write these values
'untill user put null value as i did above to get elements end nodes


i also used folloing method to put in loop as u shown,
While Element <> vbNullString
Wend

but it results in stopping my code to move forward if user enters null value, i want that when user enters null value then it will come out of that loop and move forward.

Actually the file I generated is according to ANSYS input command file, so that when i will put it in ANSYS, it will results in a frame structure in ansys and do the analysis, that's why i printed ansys command in file to automate the process.
i also want that, when i put this text file in AutoCAD again it create the same drawing in autocad, as i asked for.

thanks

nsdhakar

Tommy
04-05-2005, 11:41 AM
I think this will get the loops fixed. How much of this file is the drawing?

Could you post a DWG file in acad2000 format so I know what I am drawing? It would give me a better idea of what is going on instead of working in the dark. :)


While Not IsNull(Element)
ThisDrawing.Utility.Prompt "Apply some constraints" & Chr$(13)
Element = _
ThisDrawing.Utility.GetString(False, _
"enter the constraints on the nodes like(n,UX,0,,,UY,UZ ), " & _
"where n is the node no.:")
If Not IsNull(Element) Then
Print #intFile, "DK," & Element
End If
Wend
'Note: make this part in loop so that it can write these values
'untill user put null value as i did above to get elements end nodes
Print #intFile, " !Apply Load "

Element = "HOLD" 'force first one
While Not IsNull(Element)
Element = ThisDrawing.Utility.GetString(False, _
"enter force load to keypoints like(n,FY,-280e3),where n is the node no.:")
If Not IsNull(Element) Then Print #intFile, "FK," & Element
Wend

nsdhakar
04-05-2005, 01:52 PM
Thankyou Tommy, i am trying to run my code after doing correction as told by you. :)

i have atteched my drawing file, this is the drawing which i have taken as reference to make my text file, in all cases structure will be frame structure always, there can be varriation in no of nodes, no of elements and loads. ( means varriation in the values which are entered by user)



!Define key points

K, 1,4578.2531,7919.0487

K, 2,11346.8678,11826.9102

K, 3,11346.8678,3072.2707

K, 4,4578.2531,3072.2707

K, 5,11346.8678,7919.0487

K, 6,4578.2531,11826.9102

!Define line

L,1,2

L,2,3

L,3,4

L,4,5

L,5,6

!Element Definition


and



!Apply some constraints
DK,3,UX,0,,,UY,UZ ! define a DOF constraint at a keypoint
DK,4,UY,0,,,UZ
! apply loads
FK,1,FY,-280e3 ! define a force load to a keypoint
FK,3,FY,-210e3
FK,5,FY,-280e3
FK,7,FY,-360e3


these parts consist drawing part.

thanks :)
nsdhakar

Tommy, there is still a problem...code u have given is asking user to enter many values, but when user enters a null value than also it is asking user to enter values...a infinite loop has formed...it is continously asking for values. :(

thanks

nsdhakar

Tommy
04-06-2005, 10:55 AM
Ok this will fix the input no more continuous loop :)


While Len(Element) > 0
ThisDrawing.Utility.Prompt "Apply some constraints" & Chr$(13)
Element = _
ThisDrawing.Utility.GetString(False, _
"enter the constraints on the nodes like(n,UX,0,,,UY,UZ ), " & _
"where n is the node no.:")
If Len(Element) > 0 Then Print #intFile, "DK," & Element
Wend
Print #intFile, " !Apply Load "

Element = "HOLD" 'force first one
While Len(Element) > 0
Element = ThisDrawing.Utility.GetString(False, _
"enter force load to keypoints like(n,FY,-280e3),where n is the node no.:")
If Len(Element) > 0 Then Print #intFile, "FK," & Element
Wend


This is what you reqested. There are problems, it does not draw the lines as required, this is due to the input. It does matter which point is first and which line point goes where. also I do not understand the

!Apply some constraints
DK,3,UX,0,,,UY,UZ ! define a DOF constraint at a keypoint
DK,4,UY,0,,,UZ
! apply loads
FK,1,FY,-280e3 ! define a force load to a keypoint
FK,3,FY,-210e3
FK,5,FY,-280e3
FK,7,FY,-360e3

I do not have Architectural Desktop


Sub DrawFromTxt()
Dim intFile As Integer
Dim mPoints
Dim HldPoints() As String
Dim LinPlace() As String
Dim MyString As String
Dim OutArr As Variant
Dim OutPt(0 To 2) As Double
Dim OutPtA(0 To 2) As Double
Dim Lend As Integer
Dim LStart As Integerm
Dim pointObj As AcadPoint
Dim lineObj As AcadLine
Dim I As Integer
ReDim HldPoints(0)
ReDim LinPlace(0)
intFile = FreeFile
Open "C:\Acad\file.txt" For Input As intFile
While Not EOF(intFile)
Line Input #intFile, MyString
If InStr(1, MyString, " !Define key points ") > 0 Or _
InStr(1, MyString, "! Define Keypoints") > 0 Then
Line Input #intFile, MyString
While InStr(1, MyString, "Keypoints") = 0
If Left$(MyString, 1) = "K" Then
ReDim Preserve HldPoints(UBound(HldPoints) + 1)
HldPoints(UBound(HldPoints)) = Right(MyString, _
Len(MyString) - InStr(3, MyString, ","))
End If
Line Input #intFile, MyString
Wend
End If
If InStr(1, MyString, " !Define line ") > 0 Or InStr(1, _
MyString, "! Define Lines Linking") > 0 Then
Line Input #intFile, MyString
While InStr(1, MyString, "! element definition") = 0 And _
InStr(1, MyString, " !Element Definition") = 0
If Left$(MyString, 1) = "L" Then
ReDim Preserve LinPlace(UBound(LinPlace) + 1)
LinPlace(UBound(LinPlace)) = Right$(MyString, Len(MyString) - 2)
End If
If Not EOF(intFile) Then
Line Input #intFile, MyString
Else
MyString = "! element definition"
End If
Wend
End If
Wend
Close (intFile)
'i have the points
For I = 1 To UBound(HldPoints)
OutArr = Split(HldPoints(I), ",")
OutPt(0) = Val(OutArr(0))
OutPt(1) = Val(OutArr(1))
OutPt(2) = 0
Set pointObj = ThisDrawing.ModelSpace.AddPoint(OutPt)
pointObj.Color = acCyan
ThisDrawing.Regen acActiveViewport
Next
For I = 1 To UBound(LinPlace)
OutArr = Split(LinPlace(I), ",")
LStart = Val(OutArr(0))
Lend = Val(OutArr(1))
OutArr = Split(HldPoints(LStart), ",")
OutPt(0) = Val(OutArr(0))
OutPt(1) = Val(OutArr(1))
OutPt(2) = 0
OutArr = Split(HldPoints(Lend), ",")
OutPtA(0) = Val(OutArr(0))
OutPtA(1) = Val(OutArr(1))
OutPtA(2) = 0
Set lineObj = ThisDrawing.ModelSpace.AddLine(OutPt, OutPtA)
lineObj.Color = acCyan
ThisDrawing.Regen acActiveViewport
Next
End Sub



I forgot the drawing picture

nsdhakar
04-06-2005, 12:00 PM
:bow:
Thankyou Tommy :)

you wrote that you didn't understand the following apart...

!Apply some constraints
DK,3,UX,0,,,UY,UZ ! define a DOF constraint at a keypoint
DK,4,UY,0,,,UZ
! apply loads
FK,1,FY,-280e3 ! define a force load to a keypoint
FK,3,FY,-210e3
FK,5,FY,-280e3
FK,7,FY,-360e3

in this part not consider the following part, i think there is nop need of this part, this part just apply some constarints to structure whether support is fixed, roller or just a hinged.

!Apply some constraints
DK,3,UX,0,,,UY,UZ ! define a DOF constraint at a keypoint
DK,4,UY,0,,,UZ

but the following part

! apply loads
FK,1,FY,-280e3 ! define a force load to a keypoint
FK,3,FY,-210e3
FK,5,FY,-280e3
FK,7,FY,-360e3

this part is to define loads on the nodes, i just want to show an arrow at the nodes where user enters the force value. there is no need to
consider the value of the load.i think now it is more clear :)

and as you said about the input of the nodes....i will prompt about the node
nos, that wil be wriiten in the file...in the code u have written, it
draw line between the nodes enetered by user than it is fine with me.i think
there is problem in my text what i have given to u, i just wrote end node nos
of the element without knowing about that what is the actual node no. of some
node in the file. in my program what i did is that it assign the node no. in
following order...

first it gives higher preference to the coordinate of X.poiint having the higher
x-coordinate will assign as node 1, if two point have the same x-coordinate then
it will go to y-coordinate and give preference to point having higher Y-coordinate.
this is how my node nos are written in my text file.
i think now it will be clear to you that how file assign the node nos.
now you can see clearly that what are the end node nos of the elements and can make adjustment according to that
sorry for not making it more clear initially : pray2:

thanks again:friends:

nsdhakar

Tommy
04-06-2005, 12:23 PM
As just a question and to aid in the "error free" input how about we place a text entity with the value of the node number that the program assigns it? That way when the user enters the information the node number will be there in front so the input will be in the same format?

What do you think? :)

nsdhakar
04-06-2005, 12:28 PM
:beerchug:
yes, this a good idea, i also thought for the same but i don't know how to do it so i dropped my idea. also this idea will be more convenience to user.

now if you can do it for me then it will be more usefull.

thanks

nsdhakar

Tommy
04-06-2005, 01:25 PM
At the top in DrgLog:


Dim textObj As AcadText
Dim Cntr As Integer


in the middle where you are writing the points to the file:


INITIAL:
L = 1
' will need to do something about none points in
' For Each objPnt In objSelset the selection
If TypeOf objPnt Is AcadPoint Then ' like so

varPnt = objPnt.Coordinates
' convert X double into string with a precision of 4
X_Value = Format(varPnt(0), "#.0000")
' convert Y double into string with a precision of 4
Y_Value = Format(varPnt(1), "#.0000")
' convert Z double into string with a precision of 4
Z_Value = Format(varPnt(2), "#.0000")
Element = "K, " & L & "," & X_Value & "," & Y_Value

Print #intFile, Element
Cntr = Cntr + 1
varPnt(0) = varPnt(0) + 200
varPnt(1) = varPnt(1) + 200
'<- this number 600 may need to be adjusted
Set textObj = ThisDrawing.ModelSpace.AddText(CStr(Cntr), varPnt, 600)
textObj.Color = acRed
ThisDrawing.Regen acActiveViewport
MsgBox Element
L = L + 1
End If

Next objPnt


I would have posted earlier but I couldn't find the dimscale to resize the text so it would be readable so the number I have marked will need to be adjusted :( the last height for text used is 0.2 the dimscale is 100 so the text height would be 20 which is way to small on this drawing. I also made it red and regened on each text insert so it will show up dynamically :)

nsdhakar
04-06-2005, 03:08 PM
:clap:

thankxx Tommy, You helped me a lot.
i will try the codes u posted.
In the code you posted for text to drawing, is the load part is included??ot you working on that. :)

thanxx again

nsdhakar

nsdhakar
04-06-2005, 06:10 PM
Tommy i compiled the code of text to drawing but it is giving following error..

Run-time error '62':
Input past end of file

also the loop part is still unsolved :(
i added the code u told me to do but the same thing happening(however it stops the continous loop) when i enter null value it stops suddenly , and doesn't go forward...it ends there only:(
now what should i do to run this part properly?? :think:

code for adding the node nos in the drwaing is working nicely, :clap: it is also looking very helpfull for user to have node nos infront of him in the drawing. thankyou for this.

thanks

nsdhakar

Tommy
04-07-2005, 06:16 AM
Hi nsdhakar,

I am still working on the loads with an arrow at the locations. The input past end of file means I am not getting the file in correctbut it is also not reading the loads. I am looking for the text that is written to stop, if that changes my code will not stop. When I get finished with the loads I will look into the sorting of points into a logical (at least somewhat:)) order.

On the loops can you post the code the way you have it? I am not having the problem.

Tommy
04-07-2005, 10:33 AM
Hi nsdhakar,
This should make you a happy camper. :rofl:

nsdhakar
04-07-2005, 01:02 PM
:bow:

Tommy the code is working perfectly :clap:

the loop part is finally solved.
but one problem :doh:...actually in the code of text file to drawing , when itext file have load value like
4,FY,234
then it makes arrow at 4th node in X-direction :(, but i need it in Y direction.

after this one problem my problems will be solved completely...i thankyou for devoting your time for me :friends:

thanks
nsdhakar

Tommy
04-07-2005, 01:18 PM
LOL that is just a minor detail :thumb



Function DrwArrow(pnts() As Double)
Dim plineObj As AcadLWPolyline
Dim points(0 To 3) As Double
points(0) = pnts(0): points(1) = pnts(1)
'points(2) = pnts(0) + 500: points(3) = pnts(1) '<-this line changed
points(2) = pnts(0): points(3) = pnts(1) + 500
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
plineObj.SetWidth 0, 0, 600
End Function



In the very last for loop in "DrawFromTxt"


For I = 1 To UBound(LoadPlace)
If Len(LoadPlace(I)) > 0 Then
OutArr = Split(HldPoints(I), ",")
OutPt(0) = Val(OutArr(0)) + 500
OutPt(1) = Val(OutArr(1)) + 200
OutPt(2) = 0
Set textObj = ThisDrawing.ModelSpace.AddText(LoadPlace(I), OutPt, 600)
textObj.Color = acCyan
OutPt(0) = Val(OutArr(0)) ' + 400 '<-this line changed
OutPt(1) = Val(OutArr(1)) + 400 '<-this line changed
DrwArrow OutPt
ThisDrawing.Regen acActiveViewport
End If
Next



:friends:

Let me know if that is what you want :)

nsdhakar
04-07-2005, 02:13 PM
Tommy, actually what i want is like...

if in text file loads are like...

FK,4,FY,230
FK,1,FX,-456

than in the drawing arrow should be...
at 4th node arrow should be in Y direction (due to FY)
at 1st node arrow sholud be in X direction (due to FX)

let take another case...
in text file loads are..

FK,4,FX,230
FK,1,FX,-456

than in drawing..
at 4th node arrow should be in X direction (due to FX)
at 1st node arrow should be in X direction (due to FX)

like this FX, FY can be changed and arrows depend on these, if FX than arrow in X direction and if FY than in Y direction.

i think now you will understand what i want to do. :)

thanks

nsdhakar

Tommy
04-07-2005, 02:36 PM
I saw that coming:rotlaugh:

giv e me a few minutes and I'll Get 'er done :)

Here ya go:thumb

nsdhakar
04-07-2005, 02:55 PM
Sorry Tommy, it's not working...it draw the arrow in Y direction only :( ,but i want arrows depend on FX and FY in file.
after you made corrections arrow just shifted by some distance horizontally.

thanks

nsdhakar

Tommy
04-08-2005, 06:17 AM
Sorry this will fix the problem. I wasn't passing what I thought I was in the sub :(

nsdhakar
04-08-2005, 07:33 AM
ThankYopu Tommy...Finally it is working :clap:
You really helped me a lot....:beerchug:
finally with your help i have completed most part of my project :whistle:
Thankyou again for devoting your precious time for me, i will remeber u all the time for your grt help.
nice to meet u :friends:

Thanks
nsdhakar

Zack Barresse
04-08-2005, 10:49 AM
nsdhakar, if this is Solved, I will mark it as such. You can do so as well in the future by going to the Thread Tools --> Mark Thread Solved --> Perform Action. :yes

Take care!