;Porque mudando a sequencia dos loops da errado( ;inicio-horizonta1 fim-horizonta1 ;inicio-vertical1; fim-vertical ;inicio-horizonta2;fim-horizonta2)
;Sequencia que funciona certo ( ;inicio-horizonta1 fim-horizonta1; inicio-horizonta2; fim-horizonta2; inicio-vertical1; fim-vertical1 )
(defun c:certo()
(command "_layer" "_m" "contorno" "_c" "_yellow" "" "")
(command "_layer" "_m" "circulos" "_c" "_cyan" "" "")
(command "_layer" "_m" "textos" "_c" "_green" "" "")
(command "_layer" "_m" "cotas" "_c" "_blue" "" "")
(command "_layer" "_m" "linha centro" "_c" "_red" "" "")
(command "_layer" "_m" "retangulos" "_c" "_red" "" "")
;variaveis
(setq i 0 j 0)
(setq x 150 y 150)
(setq e40 40)
(setq e10 10)
(setq e15 15)
(setq ex 15)
(setq ey 15)
(command "_layer" "_s" "contorno" "")
;inicio-horizonta1
(setq hix ex hiy ey);inicio-linha
(setq hfx (+ e40 ex) hfy ey);fim-linha
(repeat 5
(command "_line" (list hix hiy) (list hfx hfy)"")
(setq hiy(+ hiy e10))
(setq hfy(+ hfy e10))
);fim-horizonta1
;inicio-horizonta2
(setq hix (+ ex e40 e40) hiy ey);inicio-linha
(setq hfx (+ ex e40 e40 e40) hfy ey);fim-linha
(command "_layer" "_s" "circulos" "")
(repeat 5
(command "_line" (list hix hiy) (list hfx hfy)"")
(setq hiy(+ hiy e10))
(setq hfy(+ hfy e10))
);fim-horizontal2
(command "_layer" "_s" "textos" "")
;inicio-vertical1
(setq vix(+ ex e40) viy ey);inicio-linha
(setq vfx(+ ex e40) vfy (+ e40 ey));fim-linha
(repeat 5
(command "_line" (list vix viy) (list vfx vfy )"")
(setq vix(+ vix e10))
(setq vfx(+ vfx e10))
);fim-vertical1
(command "_layer" "_s" "retangulos" "")
(command "_rectangle" (list i j)(list x y))
(setq ent1 (entlast))
(command "_offset" e15 ent1 '(10 10) "")
(command "_zoom" "_e" "")
(princ)
)
//////////////////////////////////////////////////////////////////////////////////
(defun c:errado()
(command "_layer" "_m" "contorno" "_c" "_yellow" "" "")
(command "_layer" "_m" "circulos" "_c" "_cyan" "" "")
(command "_layer" "_m" "textos" "_c" "_green" "" "")
(command "_layer" "_m" "cotas" "_c" "_blue" "" "")
(command "_layer" "_m" "linha centro" "_c" "_red" "" "")
(command "_layer" "_m" "retangulos" "_c" "_red" "" "")
;variaveis
(setq i 0 j 0)
(setq x 150 y 150)
(setq e40 40)
(setq e10 10)
(setq e15 15)
(setq ex 15)
(setq ey 15)
(command "_layer" "_s" "contorno" "")
;horizonta1
(setq hix ex hiy ey);inicio-linha
(setq hfx (+ e40 ex) hfy ey);fim-linha
(repeat 5
(command "_line" (list hix hiy) (list hfx hfy)"")
(setq hiy(+ hiy e10))
(setq hfy(+ hfy e10))
);fim-horizonta1
(command "_layer" "_s" "textos" "")
;inicio-vertical1
(setq vix(+ ex e40) viy ey);inicio-linha
(setq vfx(+ ex e40) vfy (+ e40 ey));fim-linha
(repeat 5
(command "_line" (list vix viy) (list vfx vfy )"")
(setq vix(+ vix e10))
(setq vfx(+ vfx e10))
);fim-vertical1
;inicio-horizonta2
(setq hix (+ ex e40 e40) hiy ey);inicio-linha
(setq hfx (+ ex e40 e40 e40) hfy ey);fim-linha
(command "_layer" "_s" "circulos" "")
(repeat 5
(command "_line" (list hix hiy) (list hfx hfy)"")
(setq hiy(+ hiy e10))
(setq hfy(+ hfy e10))
);fim-horizontal2
(command "_layer" "_s" "retangulos" "")
(command "_rectangle" (list i j)(list x y))
(setq ent1 (entlast))
(command "_offset" e15 ent1 '(10 10) "")
(command "_zoom" "_e" "")
(princ)
)
Solucionado! Ir para Solução.
Solucionado por hmsilva. Ir para Solução.
Solucionado por hmsilva. Ir para Solução.
Olá aco2000,
os teus dois codigos funcionam da mesma maneira, certos...
O problema é a ordem de desenho, como utilizas 'command calls' para construir o teu desenho, este fica sobre a acção dos osnaps, e a linha é 'snapada' para o end point da linha já existente...
Duas opções:
ex.
(defun c:demo ( / E10 E15 E40 ENT1 EX EY HFX HFY HIX HIY I J VFX VFY VIX VIY X Y) (setq osm (getvar 'OSMODE)) (setvar 'OSMODE 0) (command "_layer" "_m" "contorno" "_c" "_yellow" "" "") (command "_layer" "_m" "circulos" "_c" "_cyan" "" "") (command "_layer" "_m" "textos" "_c" "_green" "" "") (command "_layer" "_m" "cotas" "_c" "_blue" "" "") (command "_layer" "_m" "linha centro" "_c" "_red" "" "") (command "_layer" "_m" "retangulos" "_c" "_red" "" "") ;variaveis (setq i 0 j 0) (setq x 150 y 150) (setq e40 40) (setq e10 10) (setq e15 15) (setq ex 15) (setq ey 15) (command "_layer" "_s" "contorno" "") ;horizonta1 (setq hix ex hiy ey);inicio-linha (setq hfx (+ e40 ex) hfy ey);fim-linha (repeat 5 (command "_line" (list hix hiy) (list hfx hfy)"") (setq hiy(+ hiy e10)) (setq hfy(+ hfy e10)) );fim-horizonta1 (command "_layer" "_s" "textos" "") ;inicio-vertical1 (setq vix(+ ex e40) viy ey);inicio-linha (setq vfx(+ ex e40) vfy (+ e40 ey));fim-linha (repeat 5 (command "_line" (list vix viy) (list vfx vfy )"") (setq vix(+ vix e10)) (setq vfx(+ vfx e10)) );fim-vertical1 ;inicio-horizonta2 (setq hix (+ ex e40 e40) hiy ey);inicio-linha (setq hfx (+ ex e40 e40 e40) hfy ey);fim-linha (command "_layer" "_s" "circulos" "") (repeat 5 (command "_line" (list hix hiy) (list hfx hfy)"") (setq hiy(+ hiy e10)) (setq hfy(+ hfy e10)) );fim-horizontal2 (command "_layer" "_s" "retangulos" "") (command "_rectangle" (list i j)(list x y)) (setq ent1 (entlast)) (command "_offset" e15 ent1 '(10 10) "") (command "_zoom" "_e") (setvar 'OSMODE osm) (princ) )
Espero que ajude
aco2000 escreveu:
Obrigado funcionou perfeito.
Minha duvida é o porque declara as variáveis como local ou global, pois aparentemente funciona sem declarar?
(defun c:demo ( / E10 E15 E40 ENT1 EX EY HFX HFY HIX HIY I J VFX VFY VIX VIY X Y)aqui você declarou como local...
Fico feliz que tenha funcionado como esperado!
Por principio, as variaveis deverão ser sempre localizadas.
Quando não se declara como 'locais' estas ficam como globais, caso tenhas outro código que utilize uma/umas mesmas variaveis, e necessites testar a existencia de um valor atribuido à variavel para prosseguir com o código e nesse caso estivesse 'globalozada' o código pensaria que tudo estaria correcto, mas não estava..
ex.
(if E10
(progn
....
Mais problemas vêm com listas, quando não se localiza a variavel e se tenta criar uma lista (com a existencia de uma não localizada) o que acontece é que a lista vai ser continuada e não escrita de principio...
Convem sempre localizar as nossas variaveis... Eu não localizei a 'OSM'... falha minha...
Espero que ajude
Henrique
Não encontrou o que está procurando? Pergunte à comunidade ou compartilhe seu conhecimento.