Jump to content

Recommended Posts

Posted
16 hours ago, Sambuddy said:

Thanks for that tip. I will try to use it next time.

 

But on the script itself: how do I make the command cancel after executing itself, example pline?

image.png.3ae53a696532d3dff7d89c603d34fefc.png

 

Now that I added 3 pline commands under one script, it seems to give me a messed up drawing with the LISP, but when I paste it directly onto the commandline everything seems fine. Am I doing something wrong here?

 

Could you please help?

 

when I run the LISP, it gives me this: 

Specify start point: pline

Invalid point.

 

This is what I have on the blah.scr:

 

pline
0,0
@30<195
@97<180
@7.9375<90
@95.9550083004<0
@21.0175083004<15
@21.0175083004<105
@95.9550083004<120
@7.9375<30
@97<300
close

pline
-933.955549577344,0
@30<75
@97<60
@7.9375<330
@95.9550083004<240
@21.0175083004<255
@21.0175083004<345
@95.9550083004<0
@7.9375<270
@97<180
close

pline
-466.977774788672,808.829231939437
@30<315
@97<300
@7.9375<210
@95.9550083004<120
@21.0175083004<135
@21.0175083004<225
@95.9550083004<240
@7.9375<150
@97<60
close
close

 

 

 

When I copied and pasted the above script into Notepad it showed, as @rlx noted, blank lines between the close and pline statements.  The script also has two close statements and several blank lines at the end.  The last script statement should be followed by one "enter" but that's it.  Additional blank lines will force a re-execution of the last command given, in your script that's pline.

 

Removing the extraneous blank lines and the extra close statement should given you a good script.

 

Regarding using AutoCAD/VBA it theoretically could be done.  If your code were implemented in AutoCAD/VBA you would just needed to create an array variable to hold the coordinates of the pline that you are now calculating for the script and then make a call to addpoly.  I don't know if the VBA forms you created would transfer.  I have tried several times to instal AutoCAD/VBA and have never been successful.  It appears to me that Autodesk has abandoned VBA in favor of .net and vlisp.  

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

  • Sambuddy

    23

  • rlx

    20

  • lrm

    9

  • BIGAL

    7

Top Posters In This Topic

Posted Images

Posted

Could you show me a way on the LISP posted earlier: to run first script and the next script then next under one lisp command. Example: say I have 3 individual scripts called blah_1, blah_2, blah_3 under the same C:/temp project directory. but when I enter the command only once I would like the execution of 3 or more scripts that happen individually.

 

Please and thank you.

 

This is Irm's earlier LISP:

 

(defun C:runblah ()
(if (findfile "c:\\temp\\blah.scr")
  (command "_script" "c:\\temp\\blah.scr")
)					; end if
(princ "\nDone")
(princ)
)
Posted

I honestly do not know what is wrong with my script - the copy and paste works great but if I run a script, it comes up all messed up - I did check the spaces and such but cannot find any other way but to run the the segments individually unless there is a way I could run them under ONE command but three or more script command.

 

Please let me know if you can manipulate the lisp above to serve that purpose.

Thanks

Posted

There is nothing against one script calling another. So you make script bla1.scr and at the end of that script you put the line : 'script c:/temp/blah2' and the end of script blah2 you can call script blah3 etc.

Problem with mixing vba and lisp is that they are not aware of each other since they operate on a different level. Lisp only works in the drawing it is loaded while vba sees the whole of the autocad as an object. What this means is that vba doesn't check if your lisp is done by now so it sends the next command as soon as its finished with the first one , regardless if your lisp or script is finished.

An other dirty fix may be to remove the second pline command in your script , either entirely or replace with empty line because obviously the pline command get repeated due to a carriage return somewhere / somehow...

 

Awel, shutting down my work pc ... weekend...

 

:beer:

Posted

I tried multiple approaches to create a vlisp or script file that would execute several script (.scr) files.  I was not successful in creating one that worked.     

 

Since the OP is using Excel/VBA to create each of the scripts, I created the following Excel/VBA sub that merges three files into one .scr file (blahAll.scr) that can be referenced by the vlips program below.

 

Excel/VBA program to merge three .scr files (blah-circle.scr, blah-rectangle.scr, and blah.scr) into one file.

Sub merge_scripts()
' merges several text files
Dim file_1 As String, file_2 As String, file_3 As String, fileAll As String
Dim text As String, n As Integer
text = ""
'
file_1 = "c:\temp\blah-circle.scr"
file_2 = "c:\temp\blah-rectangle.scr"
file_3 = "c:\temp\blah.scr"
'
fileAll = "c:\temp\blahAll.scr"
Open file_1 For Input As #1
Do Until EOF(1)
    Line Input #1, textline
    text = text & textline & vbCrLf
Loop
Close #1
Open file_2 For Input As #1
Do Until EOF(1)
    Line Input #1, textline
    text = text & textline & vbCrLf
Loop
Close #1
Open file_3 For Input As #1
Do Until EOF(1)
    Line Input #1, textline
    text = text & textline & vbCrLf
Loop
'remove extra characters at end of file
n = Len(text)
text = Left(text, n - 2)
Close #1
Open fileAll For Output As #1
Print #1, text
Close #1
End Sub

VLISP program to execute a script file located in a specific folder.

 

(defun C:runAll ()
  (if (findfile "c:\\temp\\blahall.scr")
    (command "_script" "c:\\temp\\blahall.scr")
  )					; end if
  (princ "\nDone")
  (princ)
)

 

Posted

The task I was trying to address is that if I have 3 scripts that draw different geometry how can they be referenced in a script or vlisp program to all run?  I don't see how your 4 scripts address this.  

 

The following script is the merging of three scripts.

blahall.scr

circle
-70,30
15
rectang
-140,24
-112,41
pline
0,0
@30<195
@72<180
@6.35<90
@71.16400664032<0
@22.81400664032<15
@22.81400664032<105
@71.16400664032<120
@6.35<30
@72<300
close

The VBA program created it from:

blah-circle.scr

circle
-70,30
15

blah-rectangle.scr

rectang
-140,24
-112,41

blah.scr

 

pline
0,0
@30<195
@72<180
@6.35<90
@71.16400664032<0
@22.81400664032<15
@22.81400664032<105
@71.16400664032<120
@6.35<30
@72<300
close

How would you either execute all three with one command or combine them into one file so that the following will execute it?

(defun C:runAll ()
  (if (findfile "c:\\temp\\blahall.scr")
    (command "_script" "c:\\temp\\blahall.scr")
  )					; end if
  (princ "\nDone")
  (princ)
)

I couldn't get anything to work in AutoCAD so I wrote the VBA program to merge the files in Excel.

blah-files.zip

Posted (edited)

Still believe OP is missing something , maybe an empty line to much or something. Just wanted to show its possible to start one script which can call the next. But why using a script in the first place if you can send all commands from vba anyway?

 

BTW , I don't know how or why the pline command gets repeated but else start and/or begin script with a command that needs no parameters like 'regen'.

 

I suppose your osnap setting (so basic) is no issue here?

Edited by rlx
Posted (edited)

lrm if your old like me you can combine 3 files using an old DOS command been a while but it was like this as next, I used it to add the security portion to a number of lisps then compile.

 

copy file1.scr+file2.scr+file3.scr file4.scr

You can use Shell command to run it.

 

Never had a problem installing the VBA runtime for Autocad 2015-2020.  Briscad V19 its loaded. 

 

Re script above needs close then 1 blank line at end, as a test just copied and pasted to command line. Nice 3 legs. Other way is close<space> as last line to react as the Enter command.

 

 

Edited by BIGAL
Posted

"...lrm if your old like me you can combine 3 files using an old DOS command"

 

Old enough to remember when you got DOS from Seattle Computing before Bill Gates gave non-exclusive rights to IBM.

Posted

Thank you all for your inputs for this question.

Again the problem was not combining the three or more scripts since I can get the VBA excel to give me a unified script by:

Dim iCntr
    Dim strFile_Path As String
    Set ssheet2 = ThisWorkbook.Sheets("DATA_1")
    strFile_Path = "C:\temp\DATA_1.scr"
    Open strFile_Path For Output As #1
    For iCntr = 1 To 85
    Print #1, ssheet2.Range("A" & iCntr)
    Next iCntr

    Close #1

End Sub

 

the problem lies when I attempt to execute it onto CAD - all scripts at once. It appears when I execute them separately the seems to draw perfectly fine but when I combine them it comes up all messed up - the reason I asked if it was possible for one lisp, one command and multiple sub-commands to bypass this issue. you will see, as you all pointed out that when you copy and paste directly from the notepad file onto commandline everything draw nice but when I execute the same notepad - now as script - it draws all messed up.

 

thanks for your input anyways

Posted

I am not sure how I might be missing an extra space with all three combined when I can copy and paste directly for it to be fine.

 

DATA_1.scr

pline
0,0
@25.4<195
@63.5<180
@6.35<90
@62.66400664032<0
@18.21400664032<15
@18.21400664032<105
@62.66400664032<120
@6.35<30
@63.5<300
close

pline
-866.069031975485,0
@25.4<75
@63.5<60
@6.35<330
@62.66400664032<240
@18.21400664032<255
@18.21400664032<345
@62.66400664032<0
@6.35<270
@63.5<180
close

pline
-433.034515987742,750.037783121767
@25.4<315
@63.5<300
@6.35<210
@62.66400664032<120
@18.21400664032<135
@18.21400664032<225
@62.66400664032<240
@6.35<150
@63.5<60
close

pline
-28.0345159877423,-6.57400374560403
@7.9375<270
@810<180

pline
-28.0345159877423,-6.57400374560403
@810<180
@38.1<270
@810<0
@38.1<90
close


I tried this one with all alternative combinations of removing plines, adding spaces, removing CLOSE - it just does not work when I execute the LISP.

Posted

I know this might be the dumbest question anyone asked but I will pose it anyways:

Is it possible for a LISP, upon executing the command, to go into C:/temp/DATA_1.scr, copy the content, then paste it - only that way I can get it to work if it is possible or logical.

 

I do not know a way for VBA to execute the txt or script coordinates without having to install Autocad Library from VBA - this pose an issue for me so far because I am running a French computer = French office Excel and it just does not get what I am trying to tell it to.

Posted (edited)

You have a S...t load of empty lines at the end of your script. Each and every empty line reacts as enter (= repeat command)

When you use close the pline command stops by itself so no need for empty line between close and next pline command

 

gr. RLX

DATA_2.scr

Edited by rlx
Posted

even your script does not work - solution is what I was asking

image.png.5c6376e66bbaa54a8ab9fc557f5ac910.png

Posted (edited)

what are the settings for your osnap? (getvar 'osmode).Or maybe better , post the drawing after you ran the script. Looks to me like either your precision / units are setup wrong or your osnap is 'gluing' your segments together. Why else would the script run ok for everyone else (or am I the ony one)? I can't think of anything else than a setting is messing up things.

 

image.png.af140aef7cc3a0e5670faba8748f4c76.png

 

Edited by rlx
Posted

wow , that really looks like a buch of sticky lines... I must say my unit settings have even a lower precision. Now I'm no expert on 3d but your drawing also looks like a bunch of lines seeing sideways. Is it possible your ucs is not set to world? You could use the command 'plan' with option world. Or use the vpoint command to look in 3d to your drawing. But all and all , its blowing my mind why a simple script can cause such problems. Then again , my wife too can turn simple things into problems so is there such a thing as male and female scripts?

Posted

You are funnier than most I give you that!

 

My UCS is set to World and NO I do not have a third dimension since I did not specify "z" on my script. I only have @x(distance)<deg for a polar coordinate.

Posted

could you post (or mail) the actual drawing (with only the lines created by the script) or the xlsm. Maybe as a last resort comparing drawing settings could shed a light on this mystery. Although this probably doesn't explain why pasting the script does work. I do like a good mystery  🕵️‍♂️ (but only if I can find the solution  😁 ).

btw , is your autocad also French? I remember vaguely preceding commands with ._ makes sure the built in autocad commands are used , so ._pline and ._close. But I must admit I am slowly running out of ideas...

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...