# Thread: Solved: Text file to drawing

1. ## Solved: Text file to drawing

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

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

!
!

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.

thanks

nsdhakar

2. Hi nsdhakar,

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.

3. 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

4. I am looking into it. Just so you know

5. Tommy is an AutoCad/VBA God!!

6. LOL I would settle for Good (one more o)

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?

[VBA]
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

[/VBA]

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 ") .

[VBA]
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

[/VBA]

7. Thankyou Tommy,
i have made change what u posted to make change.

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

[VBA]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
[/VBA]

and

[VBA]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
[/VBA]

i also used folloing method to put in loop as u shown,
[VBA]While Element <> vbNullString
Wend
[/VBA]
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

8. 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.

[VBA]
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
[/VBA]

9. 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
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

10. Ok this will fix the input no more continuous loop

[VBA]
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
[/VBA]

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
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

[VBA]
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 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
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
lineObj.Color = acCyan
ThisDrawing.Regen acActiveViewport
Next
End Sub

[/VBA]

I forgot the drawing picture

11. 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
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

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

thanks again

nsdhakar

12. 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?

13. 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

14. At the top in DrgLog:

[VBA]
Dim Cntr As Integer
[/VBA]

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

[VBA]
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
[/VBA]

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

15. 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

16. 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??

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

thanks

nsdhakar

17. 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.

18. Hi nsdhakar,
This should make you a happy camper.

19. Tommy the code is working perfectly

the loop part is finally solved.
but one problem ...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

thanks
nsdhakar

20. LOL that is just a minor detail

[VBA]
Function DrwArrow(pnts() As Double)
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
plineObj.SetWidth 0, 0, 600
End Function

[/VBA]

In the very last for loop in "DrawFromTxt"

[VBA]
For I = 1 To UBound(LoadPlace)
OutArr = Split(HldPoints(I), ",")
OutPt(0) = Val(OutArr(0)) + 500
OutPt(1) = Val(OutArr(1)) + 200
OutPt(2) = 0
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

[/VBA]

Let me know if that is what you want

#### Posting Permissions

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